Skip to content

Commit

Permalink
Refactor Tycho to use copied application
Browse files Browse the repository at this point in the history
P2 and Tycho have different demands when it comes to "Applications" e.g.
Tycho often want to programmatically set things, while in P2 they are
called in means of CLI. Also in the past it has shown its very hard to
maintain "extensibility" together with "compatibility".

Because of this, this now also imports the set of Publisher applications
to Tycho, this will open us with a large set of new opportunities e.g.
getting rid of argument building just that these arguments are later
passed back into fields/objects.
  • Loading branch information
laeubi committed Mar 11, 2024
1 parent a81b55d commit f4752ed
Show file tree
Hide file tree
Showing 9 changed files with 494 additions and 511 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,82 +12,81 @@
* Contributors:
* EclipseSource - initial API and implementation
******************************************************************************/
package org.eclipse.equinox.internal.p2.updatesite;
package org.eclipse.tycho.p2tools.copiedfromp2;

import java.net.URI;
import java.net.URISyntaxException;

import org.eclipse.core.runtime.URIUtil;
import org.eclipse.equinox.internal.p2.updatesite.CategoryXMLAction;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.publisher.*;
import org.eclipse.equinox.p2.publisher.IPublisherAction;
import org.eclipse.equinox.p2.publisher.Publisher;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;

/**
* <p>
* This application categorizes the elements in a repo based on a category
* definition file. The category definition file is specified with
* <source>-categoryDefinition</source>
* This application categorizes the elements in a repo based on a category definition file. The
* category definition file is specified with <source>-categoryDefinition</source>
* </p>
*/
public class CategoryPublisherApplication extends AbstractPublisherApplication {

private String categoryQualifier = null;
private URI categoryDefinition = null;

public CategoryPublisherApplication() {
super();
}
private String categoryQualifier = null;
private URI categoryDefinition = null;

public CategoryPublisherApplication(IProvisioningAgent agent) {
super(agent);
}
public CategoryPublisherApplication(IProvisioningAgent agent) {
super(agent);
}

/*
* Check to see if an existing repository already has the "compressed" flag set
*/
@Override
protected void initializeRepositories(PublisherInfo publisherInfo) throws ProvisionException {
try {
if (metadataLocation != null) {
// Try to load the metadata repository. If it loads, check the "compressed"
// flag, and cache it.
// If there are any errors loading it (i.e. it doesn't exist), just skip this
// step
// If there are serious problems with the repository, the superclass
// initializeRepositories method
// will handle it.
IMetadataRepository result = Publisher.loadMetadataRepository(agent, metadataLocation, true, true);
if (result != null) {
Object property = result.getProperties().get(IRepository.PROP_COMPRESSED);
if (property != null) {
boolean compressProperty = Boolean.valueOf((String) property);
this.compress = compressProperty || compress;
}
}
}
} catch (ProvisionException e) {
// do nothing
}
super.initializeRepositories(publisherInfo);
}
/*
* Check to see if an existing repository already has the "compressed" flag set
*/
@Override
protected void initializeRepositories(PublisherInfo publisherInfo) throws ProvisionException {
try {
if (metadataLocation != null) {
// Try to load the metadata repository. If it loads, check the "compressed"
// flag, and cache it.
// If there are any errors loading it (i.e. it doesn't exist), just skip this
// step
// If there are serious problems with the repository, the superclass
// initializeRepositories method
// will handle it.
IMetadataRepository result = Publisher.loadMetadataRepository(agent, metadataLocation, true, true);
if (result != null) {
Object property = result.getProperties().get(IRepository.PROP_COMPRESSED);
if (property != null) {
boolean compressProperty = Boolean.valueOf((String) property);
this.compress = compressProperty || compress;
}
}
}
} catch (ProvisionException e) {
// do nothing
}
super.initializeRepositories(publisherInfo);
}

@Override
protected void processParameter(String arg, String parameter, PublisherInfo pinfo) throws URISyntaxException {
super.processParameter(arg, parameter, pinfo);
@Override
protected void processParameter(String arg, String parameter, PublisherInfo pinfo) throws URISyntaxException {
super.processParameter(arg, parameter, pinfo);

this.append = true; // Always append, otherwise we will end up with nothing
this.append = true; // Always append, otherwise we will end up with nothing

if (arg.equalsIgnoreCase("-categoryQualifier")) //$NON-NLS-1$
categoryQualifier = parameter;
if (arg.equalsIgnoreCase("-categoryQualifier")) //$NON-NLS-1$
categoryQualifier = parameter;

if (arg.equalsIgnoreCase("-categoryDefinition")) //$NON-NLS-1$
categoryDefinition = URIUtil.fromString(parameter);
if (arg.equalsIgnoreCase("-categoryDefinition")) //$NON-NLS-1$
categoryDefinition = URIUtil.fromString(parameter);

}
}

@Override
protected IPublisherAction[] createActions() {
return new IPublisherAction[] { new CategoryXMLAction(categoryDefinition, categoryQualifier) };
}
}
@Override
protected IPublisherAction[] createActions() {
return new IPublisherAction[] { new CategoryXMLAction(categoryDefinition, categoryQualifier) };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,86 +12,86 @@
* Contributors:
* Code 9 - initial API and implementation
******************************************************************************/
package org.eclipse.equinox.p2.publisher.eclipse;
package org.eclipse.tycho.p2tools.copiedfromp2;

import java.io.File;
import java.net.URISyntaxException;
import java.util.ArrayList;

import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.metadata.Version;
import org.eclipse.equinox.p2.publisher.*;
import org.eclipse.equinox.p2.publisher.AbstractPublisherAction;
import org.eclipse.equinox.p2.publisher.IPublisherAction;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
import org.eclipse.equinox.p2.publisher.actions.RootIUAction;
import org.eclipse.equinox.p2.publisher.actions.RootIUResultFilterAdvice;
import org.eclipse.equinox.p2.publisher.eclipse.FeaturesAction;
import org.eclipse.tycho.p2maven.tmp.BundlesAction;

/**
* <p>
* This application generates meta-data and artifact repositories from a set of
* features and bundles. If {@code -source <localdir>} parameter is given, it
* specifies the directory under which to find the features and bundles (in the
* standard "features" and "plugins" sub-directories).
* This application generates meta-data and artifact repositories from a set of features and
* bundles. If {@code -source <localdir>} parameter is given, it specifies the directory under which
* to find the features and bundles (in the standard "features" and "plugins" sub-directories).
* </p>
* <p>
* Optionally, the {@code -features <csv of file locations>} and
* {@code -bundles <csv} of file locations> arguments can be specified. If
* given, these override the defaults derived from a supplied -source parameter.
* Optionally, the {@code -features <csv of file locations>} and {@code -bundles <csv} of file
* locations> arguments can be specified. If given, these override the defaults derived from a
* supplied -source parameter.
* </p>
*/
public class FeaturesAndBundlesPublisherApplication extends AbstractPublisherApplication {

protected File[] features = null;
protected File[] bundles = null;

protected String rootIU = null;
protected String rootVersion = null;
protected File[] features = null;
protected File[] bundles = null;

public FeaturesAndBundlesPublisherApplication() {
super();
}
protected String rootIU = null;
protected String rootVersion = null;

public FeaturesAndBundlesPublisherApplication(IProvisioningAgent agent) {
super(agent);
}
public FeaturesAndBundlesPublisherApplication(IProvisioningAgent agent) {
super(agent);
}

@Override
protected void processParameter(String arg, String parameter, PublisherInfo pinfo) throws URISyntaxException {
super.processParameter(arg, parameter, pinfo);
@Override
protected void processParameter(String arg, String parameter, PublisherInfo pinfo) throws URISyntaxException {
super.processParameter(arg, parameter, pinfo);

if (arg.equalsIgnoreCase("-features")) //$NON-NLS-1$
features = createFiles(parameter);
if (arg.equalsIgnoreCase("-features")) //$NON-NLS-1$
features = createFiles(parameter);

if (arg.equalsIgnoreCase("-bundles")) //$NON-NLS-1$
bundles = createFiles(parameter);
if (arg.equalsIgnoreCase("-bundles")) //$NON-NLS-1$
bundles = createFiles(parameter);

if (arg.equalsIgnoreCase("-iu")) //$NON-NLS-1$
rootIU = parameter;
if (arg.equalsIgnoreCase("-iu")) //$NON-NLS-1$
rootIU = parameter;

if (arg.equalsIgnoreCase("-version")) //$NON-NLS-1$
rootVersion = parameter;
}
if (arg.equalsIgnoreCase("-version")) //$NON-NLS-1$
rootVersion = parameter;
}

private File[] createFiles(String parameter) {
String[] filespecs = AbstractPublisherAction.getArrayFromString(parameter, ","); //$NON-NLS-1$
File[] result = new File[filespecs.length];
for (int i = 0; i < filespecs.length; i++)
result[i] = new File(filespecs[i]);
return result;
}
private File[] createFiles(String parameter) {
String[] filespecs = AbstractPublisherAction.getArrayFromString(parameter, ","); //$NON-NLS-1$
File[] result = new File[filespecs.length];
for (int i = 0; i < filespecs.length; i++)
result[i] = new File(filespecs[i]);
return result;
}

@Override
protected IPublisherAction[] createActions() {
ArrayList<IPublisherAction> result = new ArrayList<>();
if (features == null)
features = new File[] {new File(source, "features")}; //$NON-NLS-1$
result.add(new FeaturesAction(features));
if (bundles == null)
bundles = new File[] {new File(source, "plugins")}; //$NON-NLS-1$
result.add(new BundlesAction(bundles));
@Override
protected IPublisherAction[] createActions() {
ArrayList<IPublisherAction> result = new ArrayList<>();
if (features == null)
features = new File[] { new File(source, "features") }; //$NON-NLS-1$
result.add(new FeaturesAction(features));
if (bundles == null)
bundles = new File[] { new File(source, "plugins") }; //$NON-NLS-1$
result.add(new BundlesAction(bundles));

if (rootIU != null) {
result.add(new RootIUAction(rootIU, Version.parseVersion(rootVersion), rootIU));
info.addAdvice(new RootIUResultFilterAdvice(null));
}
if (rootIU != null) {
result.add(new RootIUAction(rootIU, Version.parseVersion(rootVersion), rootIU));
info.addAdvice(new RootIUResultFilterAdvice(null));
}

return result.toArray(new IPublisherAction[result.size()]);
}
return result.toArray(new IPublisherAction[result.size()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,64 @@
* Contributors:
* Code 9 - initial API and implementation
******************************************************************************/
package org.eclipse.equinox.internal.p2.updatesite;
package org.eclipse.tycho.p2tools.copiedfromp2;

import java.net.URISyntaxException;

import org.eclipse.equinox.internal.p2.updatesite.LocalUpdateSiteAction;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.publisher.*;
import org.eclipse.equinox.p2.publisher.IPublisherAction;
import org.eclipse.equinox.p2.publisher.PublisherInfo;
import org.eclipse.equinox.p2.publisher.actions.JREAction;

/**
* <p>
* This application generates meta-data/artifact repositories from a local
* update site. The -source <localdir> parameter must specify the top-level
* directory containing the update site.
* This application generates meta-data/artifact repositories from a local update site. The -source
* <localdir> parameter must specify the top-level directory containing the update site.
* </p>
*/
public class UpdateSitePublisherApplication extends AbstractPublisherApplication {

private String categoryQualifier = null;
private String categoryVersion = null;

public UpdateSitePublisherApplication() {
super();
}
private String categoryQualifier = null;
private String categoryVersion = null;

public UpdateSitePublisherApplication(IProvisioningAgent agent) {
super(agent);
}
public UpdateSitePublisherApplication(IProvisioningAgent agent) {
super(agent);
}

@Override
protected void processParameter(String arg, String parameter, PublisherInfo pinfo) throws URISyntaxException {
super.processParameter(arg, parameter, pinfo);
@Override
protected void processParameter(String arg, String parameter, PublisherInfo pinfo) throws URISyntaxException {
super.processParameter(arg, parameter, pinfo);

if (arg.equalsIgnoreCase("-categoryQualifier")) //$NON-NLS-1$
categoryQualifier = parameter;
if (arg.equalsIgnoreCase("-categoryQualifier")) //$NON-NLS-1$
categoryQualifier = parameter;

if (arg.equalsIgnoreCase("-categoryVersion")) //$NON-NLS-1$
categoryVersion = parameter;
}
if (arg.equalsIgnoreCase("-categoryVersion")) //$NON-NLS-1$
categoryVersion = parameter;
}

@Override
protected IPublisherAction[] createActions() {
LocalUpdateSiteAction action = new LocalUpdateSiteAction(source, categoryQualifier);
action.setCategoryVersion(categoryVersion);
if (addJRE) {
return new IPublisherAction[] { action, new JREAction((String) null) };
}
return new IPublisherAction[] { action };
}
@Override
protected IPublisherAction[] createActions() {
LocalUpdateSiteAction action = new LocalUpdateSiteAction(source, categoryQualifier);
action.setCategoryVersion(categoryVersion);
if (addJRE) {
return new IPublisherAction[] { action, new JREAction((String) null) };
}
return new IPublisherAction[] { action };
}

/** by default don't generate the JRE IU */
private boolean addJRE = false;
/** by default don't generate the JRE IU */
private boolean addJRE = false;

/**
* Detect the flag -addJREIU to turn on the generation of the JREIU.
*/
@Override
protected void processFlag(String flag, PublisherInfo publisherInfo) {
super.processFlag(flag, publisherInfo);
if (flag.equalsIgnoreCase("-addJREIU"))//$NON-NLS-1$
{
addJRE = true;
}
}
/**
* Detect the flag -addJREIU to turn on the generation of the JREIU.
*/
@Override
protected void processFlag(String flag, PublisherInfo publisherInfo) {
super.processFlag(flag, publisherInfo);
if (flag.equalsIgnoreCase("-addJREIU"))//$NON-NLS-1$
{
addJRE = true;
}
}
}
Loading

0 comments on commit f4752ed

Please sign in to comment.