Skip to content

Commit

Permalink
JBIDE-28979: Update tycho plugins to 4.0.3 (#96)
Browse files Browse the repository at this point in the history
* JBIDE-28979: Update tycho plugins to 4.0.3

Signed-off-by: Stephane Bouchet <sbouchet@redhat.com>

* JBIDE-28979: Update tycho plugins to 4.0.3

Signed-off-by: Stephane Bouchet <sbouchet@redhat.com>

* fix tests

Signed-off-by: Stephane Bouchet <sbouchet@redhat.com>

---------

Signed-off-by: Stephane Bouchet <sbouchet@redhat.com>
  • Loading branch information
sbouchet authored Oct 4, 2023
1 parent bbbe13a commit 5042ae2
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 107 deletions.
2 changes: 1 addition & 1 deletion tycho-plugins/enforcer-rules/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<parent>
<groupId>org.jboss.tools</groupId>
<artifactId>tycho-plugins</artifactId>
<version>4.0.3-SNAPSHOT</version>
<version>4.0.3</version>
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions tycho-plugins/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<artifactId>tycho-plugins</artifactId>
<packaging>pom</packaging>
<name>jbosstools-tycho-plugins-parent</name>
<version>4.0.3-SNAPSHOT</version>
<version>4.0.3</version>
<properties>
<tychoVersion>4.0.2</tychoVersion>
<tychoVersion>4.0.3</tychoVersion>
<maven.version>3.9.4</maven.version>
<!-- if https://issues.jboss.org/browse/JBIDE-22248 comes back, use
<jbossNexus>origin-repository.jboss.org</jbossNexus> -->
Expand Down
9 changes: 2 additions & 7 deletions tycho-plugins/repository-utils/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.jboss.tools</groupId>
<artifactId>tycho-plugins</artifactId>
<version>4.0.3-SNAPSHOT</version>
<version>4.0.3</version>
</parent>

<properties>
Expand Down Expand Up @@ -96,12 +96,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-io</artifactId>
<version>2.0.4</version>
<version>4.8.0</version>
</dependency>
<!-- Tycho -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,32 @@
public class GenerateRepositoryFacadeMojo extends AbstractTychoPackagingMojo {

private enum ReferenceStrategy {
embedReferences, compositeReferences
embedReferences,
compositeReferences
}

public static final Set<String> defaultSystemProperties = new HashSet<>(Arrays.asList(new String[] {
// these are all parameters of the Jenkins job; if not set they'll be null
// TODO should default to null or "" ?
"BUILD_ALIAS", "JOB_NAME", "BUILD_NUMBER", "RELEASE", "ZIPSUFFIX", "TARGET_PLATFORM_VERSION",
"TARGET_PLATFORM_VERSION_MAXIMUM", "NODE_NAME", // The name of the node the current build is running on

// these are environment variables so should be valid when run in Jenkins or for
// local builds
"HOSTNAME", // replaces HUDSON_SLAVE: more portable & means the same thing
"WORKSPACE", // likely the same as user.dir, unless -DWORKSPACE= used to override
"os.name", "os.version", "os.arch", "java.vendor", "java.version", "user.dir" }));
public static final Set<String> defaultSystemProperties = new HashSet<String>(Arrays.asList(new String[] {
// these are all parameters of the Jenkins job; if not set they'll be null
// TODO should default to null or "" ?
"BUILD_ALIAS",
"JOB_NAME",
"BUILD_NUMBER",
"RELEASE",
"ZIPSUFFIX",
"TARGET_PLATFORM_VERSION",
"TARGET_PLATFORM_VERSION_MAXIMUM",
"NODE_NAME", // The name of the node the current build is running on

// these are environment variables so should be valid when run in Jenkins or for local builds
"HOSTNAME", // replaces HUDSON_SLAVE: more portable & means the same thing
"WORKSPACE", // likely the same as user.dir, unless -DWORKSPACE= used to override
"os.name",
"os.version",
"os.arch",
"java.vendor",
"java.version",
"user.dir"
}));

private static final String UPSTREAM_ELEMENT = "upstream";
public static final String BUILDINFO_JSON = "buildinfo.json";
Expand All @@ -127,8 +139,8 @@ private enum ReferenceStrategy {
private File siteTemplateFolder;

/**
* Additional files to add to repo and that are not in the "siteTemplateFolder".
* These can be folders.
* Additional files to add to repo and that are not in the
* "siteTemplateFolder". These can be folders.
*/
@Parameter
private List<File> additionalWebResources;
Expand All @@ -141,25 +153,25 @@ private enum ReferenceStrategy {

/**
* This can have 2 values: embedReferences or compositeReferences.
* "embedReferences" will add the repository references directly to the
* content.jar of the repository. "compositeReferences" will add repository
* references to a new external content.xml and will create a composite that
* composite both content and references. Then top-level repository won't
* contain any reference to other repo whereas repository in "withreferences"
* will composite the top-level repo, with the additional repo adding references
* to associateSites
* "embedReferences" will add the repository references directly to the content.jar
* of the repository.
* "compositeReferences" will add repository references to a new external content.xml
* and will create a composite that composite both content and references. Then top-level
* repository won't contain any reference to other repo whereas repository in "withreferences"
* will composite the top-level repo, with the additional repo adding references to
* associateSites
*
* "compositeReferences" is preferred in case your site is used by an upstream
* project that will manage the dependencies since its output is actually 2
* sites: one without the references for integrators, and one with references
* for testers/users who just want dependencies to come without adding sites, so
* relying on references.
* "compositeReferences" is preferred in case your site is used by an upstream project
* that will manage the dependencies since its output is actually 2 sites: one without
* the references for integrators, and one with references for testers/users who just
* want dependencies to come without adding sites, so relying on references.
*/
@Parameter(defaultValue = "embedReferences")
private ReferenceStrategy referenceStrategy;

/**
* name of the file in ${siteTemplateFolder} to use as template for index.html
* name of the file in ${siteTemplateFolder} to use as template for
* index.html
*/
@Parameter(defaultValue = "index.html")
private String indexName;
Expand Down Expand Up @@ -198,10 +210,9 @@ private enum ReferenceStrategy {
private EclipseRepositoryProject eclipseRepositoryProject;

/**
* In case some content is missing on site, use alternate URL pattern as
* fallback, if provided. Eg, search
* http://download.jboss.org/jbosstools/mars/snapshots/builds/jbosstools-base_master/latest/all/repo/buildinfo.json
* instead of
* In case some content is missing on site, use alternate URL pattern as fallback, if provided.
* Eg, search
* http://download.jboss.org/jbosstools/mars/snapshots/builds/jbosstools-base_master/latest/all/repo/buildinfo.json instead of
* http://download.jboss.org/jbosstools/mars/snapshots/builds/jbosstools-base_master/buildinfo.json
*/
@Parameter(defaultValue = "latest/all/repo")
Expand Down Expand Up @@ -291,8 +302,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
}

if (!skipBuildInfo) {
// collect buildinfo.json files from upstream and store them in
// target/buildinfo/
// collect buildinfo.json files from upstream and store them in target/buildinfo/
// also save a copy of the merged buildinfo.json in target/repository/
createBuildInfo(outputRepository, buildinfoFolder);
}
Expand Down Expand Up @@ -321,19 +331,17 @@ private void createCompositeReferences(File outputRepository, List<String> assoc
referencesDir.mkdir();
File contentXmlReference = new File(referencesDir, "content.xml");
StringBuilder content = new StringBuilder();
content.append("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>").append('\n')
.append("<?metadataRepository version='1.1.0'?>").append('\n')
.append("<repository name='References for").append(repoName)
.append("' type='org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository' version='1'>")
.append('\n').append(" <properties size='1'>").append('\n')
.append(" <property name='p2.timestamp' value='").append(timestamp).append("'/>").append('\n')
.append(" </properties>").append('\n').append(" <references size='")
.append(2 * associateSites2.size()).append("'>").append('\n');
content
.append("<?xml version='1.0' encoding='UTF-8' standalone='yes'?>").append('\n')
.append("<?metadataRepository version='1.1.0'?>").append('\n')
.append("<repository name='References for").append(repoName).append("' type='org.eclipse.equinox.internal.p2.metadata.repository.LocalMetadataRepository' version='1'>").append('\n')
.append(" <properties size='1'>").append('\n')
.append(" <property name='p2.timestamp' value='").append(timestamp).append("'/>").append('\n')
.append(" </properties>").append('\n')
.append(" <references size='").append(2 * associateSites2.size()).append("'>").append('\n');
for (String site : associateSites2) {
content.append(" <repository options='1' type='0' uri='").append(site).append("' url='").append(site)
.append("'/>").append('\n');
content.append(" <repository options='1' type='1' uri='").append(site).append("' url='").append(site)
.append("'/>").append('\n');
content.append(" <repository options='1' type='0' uri='").append(site).append("' url='").append(site).append("'/>").append('\n');
content.append(" <repository options='1' type='1' uri='").append(site).append("' url='").append(site).append("'/>").append('\n');
}
content.append(" </references>").append('\n');
content.append("</repository>");
Expand All @@ -346,29 +354,32 @@ private void createCompositeReferences(File outputRepository, List<String> assoc
File compositeContentXml = new File(compositeWithRefDir, "compositeContent.xml");
StringBuilder compositeContent = new StringBuilder();
compositeContent.append("<?compositeMetadataRepository version='1.0.0'?>").append('\n')
.append("<repository name='").append(repoName)
.append("' type='org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository' version='1.0.0'>")
.append('\n').append(" <properties size='2'>").append('\n')
.append(" <property name='p2.compressed' value='true'/>").append('\n')
.append(" <property name='p2.timestamp' value='").append(timestamp).append("'/>").append('\n')
.append(" </properties>").append("\n").append(" <children size='2'>").append("\n")
.append(" <child location='../'/>").append('\n').append(" <child location='../references'/>")
.append('\n').append(" </children>").append('\n').append("</repository>");
.append("<repository name='").append(repoName).append("' type='org.eclipse.equinox.internal.p2.metadata.repository.CompositeMetadataRepository' version='1.0.0'>").append('\n')
.append(" <properties size='2'>").append('\n')
.append(" <property name='p2.compressed' value='true'/>").append('\n')
.append(" <property name='p2.timestamp' value='").append(timestamp).append("'/>").append('\n')
.append(" </properties>").append("\n")
.append(" <children size='2'>").append("\n")
.append(" <child location='../'/>").append('\n')
.append(" <child location='../references'/>").append('\n')
.append(" </children>").append('\n')
.append("</repository>");
org.apache.commons.io.FileUtils.writeStringToFile(compositeContentXml, compositeContent.toString(),
StandardCharsets.UTF_8);
}
{
File compositeArtifactsXml = new File(compositeWithRefDir, "compositeArtifacts.xml");
StringBuilder compositeArtifact = new StringBuilder();
compositeArtifact.append("<?compositeArtifactRepository version='1.0.0'?>").append('\n')
.append("<repository name='").append(repoName)
.append("' type='org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository' version='1.0.0'>")
.append('\n').append(" <properties size='2'>").append('\n')
.append(" <property name='p2.compressed' value='true'/>").append('\n')
.append(" <property name='p2.timestamp' value='").append(timestamp).append("'/>").append('\n')
.append(" </properties>").append("\n").append(" <children size='1'>").append("\n")
.append(" <child location='../'/>").append('\n').append(" </children>").append('\n')
.append("</repository>");
.append("<repository name='").append(repoName).append("' type='org.eclipse.equinox.internal.p2.artifact.repository.CompositeArtifactRepository' version='1.0.0'>").append('\n')
.append(" <properties size='2'>").append('\n')
.append(" <property name='p2.compressed' value='true'/>").append('\n')
.append(" <property name='p2.timestamp' value='").append(timestamp).append("'/>").append('\n')
.append(" </properties>").append("\n")
.append(" <children size='1'>").append("\n")
.append(" <child location='../'/>").append('\n')
.append(" </children>").append('\n')
.append("</repository>");
org.apache.commons.io.FileUtils.writeStringToFile(compositeArtifactsXml, compositeArtifact.toString(),
StandardCharsets.UTF_8);
}
Expand Down Expand Up @@ -414,8 +425,7 @@ private void generateSiteProperties(File outputRepository, File outputCategoryXm
}

/*
* This version of category.xml (including feature/bundle versions) is used to
* generate list of features in site.properties and index.html
* This version of category.xml (including feature/bundle versions) is used to generate list of features in site.properties and index.html
*/
private File generateCategoryXml(File outputRepository) throws MojoExecutionException {
// Generate category.xml
Expand Down Expand Up @@ -460,9 +470,10 @@ public boolean visitFeature(FeatureDescription feature) {
}

/**
* Alter content.xml, content.jar, content.xml.xz to: remove default
* "Uncategorized" category, remove 3rd party associate sites, and add associate
* sites defined in site's pom.xml
* Alter content.xml, content.jar, content.xml.xz to:
* remove default "Uncategorized" category,
* remove 3rd party associate sites, and
* add associate sites defined in site's pom.xml
*
* @param p2repository
* @throws FileNotFoundException
Expand Down Expand Up @@ -552,8 +563,8 @@ private void alterContentJar(File p2repository) throws FileNotFoundException, IO
}

/**
* Add p2 stats to the repository's artifacts.xml (and .jar and .xml.xz) See
* http://wiki.eclipse.org/Equinox_p2_download_stats
* Add p2 stats to the repository's artifacts.xml (and .jar and .xml.xz)
* See http://wiki.eclipse.org/Equinox_p2_download_stats
*
* @param p2repository
* @throws FileNotFoundException
Expand Down Expand Up @@ -625,8 +636,8 @@ private void addP2Stats(File p2repository) throws FileNotFoundException, IOExcep
}

/**
* Add p2 stats to the repository's artifacts.xml (and .jar and .xml.xz) See
* http://wiki.eclipse.org/Equinox_p2_download_stats
* Add p2 stats to the repository's artifacts.xml (and .jar and .xml.xz)
* See http://wiki.eclipse.org/Equinox_p2_download_stats
*
* @param theXml
* @param theXmlXz
Expand All @@ -641,14 +652,11 @@ private void alterXzFile(File theXml, File theXmlXz, Transformer transformer, DO
try {
// JBDS-3929 overwrite the artifacts.xml.xz file too
// see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=464614
// getLog().debug("delete " + theXmlXz.toString());
FileUtils.forceDelete(theXmlXz);
// getLog().debug("create " + theXml.toString() + " from transformed XML");
FileOutputStream outStreamXml = new FileOutputStream(theXml);
StreamResult resultXml = new StreamResult(outStreamXml);
transformer.transform(source, resultXml);
outStreamXml.close();
// getLog().debug("stream " + theXml.toString() + " to " + theXmlXz.toString());
BufferedInputStream in = new BufferedInputStream(new FileInputStream(theXml));
XZCompressorOutputStream out = new XZCompressorOutputStream(new FileOutputStream(theXmlXz));
final byte[] buffer = new byte[1024];
Expand All @@ -658,8 +666,6 @@ private void alterXzFile(File theXml, File theXmlXz, Transformer transformer, DO
}
out.close();
in.close();
// getLog().debug("new " + theXmlXz.toString() + " written; remove " +
// theXml.toString());
FileUtils.forceDelete(theXml);
} catch (IOException | TransformerException ex) {
getLog().error(ex);
Expand Down Expand Up @@ -876,26 +882,15 @@ private void writeUpstreamBuildinfoJSONFile(ModelNode obj, File buildinfoFolder)
}
}

// for a given JSON object, find /revision/knownReferences[0]/url, then extract
// the project name from the git repo URL
// for a given JSON object, find /revision/knownReferences[0]/url, then extract the project name from the git repo URL
private String getProjectName(ModelNode obj) {
String projectURL = null;
String projectName = null;
for (Property prop : obj.get("revision").asPropertyList()) {
if (projectURL == null && prop.getName().equals("knownReferences") && prop.getValue().isDefined()) { // this
// is
// a
// ModelNode;
// want
// the
// zeroth
// named
// key
// "url"
if (projectURL == null && prop.getName().equals("knownReferences") && prop.getValue().isDefined()) { // this is a ModelNode; want the zeroth named key "url"
projectURL = prop.getValue().asList().get(0).get("url").asString();
getLog().debug("Upstream repo: " + projectURL);
// JBIDE-22808 support both git://github.com/jbosstools/jbosstools-portlet.git
// and https://github.com/jbosstools/jbosstools-arquillian formats
// JBIDE-22808 support both git://github.com/jbosstools/jbosstools-portlet.git and https://github.com/jbosstools/jbosstools-arquillian formats
projectName = projectURL.replaceAll(".+/([^/]+).git", "$1").replaceAll(".+/([^/]+)", "$1");
getLog().debug("Upstream proj: " + projectName);
}
Expand All @@ -907,15 +902,16 @@ private ModelNode createRevisionObject() throws IOException, FileNotFoundExcepti
ModelNode res = new ModelNode();
File repoRoot = findRepoRoot(this.project.getBasedir());
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository gitRepo = builder.setGitDir(new File(repoRoot, ".git")).readEnvironment() // scan environment GIT_*
// variables
Repository gitRepo = builder.setGitDir(new File(repoRoot, ".git"))
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
Ref head = gitRepo.exactRef(Constants.HEAD);
res.get("HEAD").set(head.getObjectId().getName());
if (head.getTarget() != null && head.getTarget().getName() != null) {
res.get("currentBranch").set(head.getTarget().getName());
}

ModelNode knownReferences = new ModelNode();
for (Ref entry : gitRepo.getRefDatabase().getRefs()) {
if (entry.getName().startsWith(Constants.R_REMOTES)
Expand All @@ -926,7 +922,9 @@ private ModelNode createRevisionObject() throws IOException, FileNotFoundExcepti
String remoteUrl = gitRepo.getConfig().getString("remote", remoteName, "url");
String branchName = entry.getName().substring(Constants.R_REMOTES.length() + 1 + remoteName.length());
reference.get("name").set(remoteName);
reference.get("url").set(remoteUrl);
//remote url on github action is not properly retrieved because of detached HEAD and pull request, make this workaround to pass test
if (remoteUrl != null)
reference.get("url").set(remoteUrl);
reference.get("ref").set(branchName);
knownReferences.add(reference);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.tools</groupId>
<version>4.0.2-SNAPSHOT</version>
<version>4.0.3</version>
<artifactId>org.jboss.tools.site.central.fetch-from-manifests.example</artifactId>
<packaging>eclipse-repository</packaging>
<properties>
Expand All @@ -16,7 +16,7 @@
<plugin>
<groupId>org.jboss.tools.tycho-plugins</groupId>
<artifactId>repository-utils</artifactId>
<version>4.0.3-SNAPSHOT</version>
<version>4.0.3</version>
<executions>
<execution>
<id>fetch-sources</id>
Expand Down
Loading

0 comments on commit 5042ae2

Please sign in to comment.