-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #844 from eclipse-passage/553630/complete_pom
Bug 553630 [Passage] publish general purpose passage bundles
- Loading branch information
Showing
4 changed files
with
340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2021 ArSysOp and others | ||
This program and the accompanying materials are made available under the | ||
terms of the Eclipse Public License 2.0 which is available at | ||
https://www.eclipse.org/legal/epl-2.0/. | ||
SPDX-License-Identifier: EPL-2.0 | ||
Contributors: | ||
ArSysOp - initial API and implementation | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
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.eclipse.passage</groupId> | ||
<artifactId>org.eclipse.passage.releng.pommod</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<java.version>1.8</java.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-model</artifactId> | ||
<version>3.5.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-utils</artifactId> | ||
<version>3.1.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>args4j</groupId> | ||
<artifactId>args4j</artifactId> | ||
<version>2.33</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jdt</groupId> | ||
<artifactId>org.eclipse.jdt.annotation</artifactId> | ||
<version>2.1.100</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<defaultGoal>clean verify</defaultGoal> | ||
<finalName>pommod</finalName> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.7.0</version> | ||
<configuration> | ||
<source>${java.version}</source> | ||
<target>${java.version}</target> | ||
</configuration> | ||
</plugin> | ||
<!-- Create an executable jar for this tool --> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-shade-plugin</artifactId> | ||
<version>3.1.1</version> | ||
<executions> | ||
<execution> | ||
<phase>package</phase> | ||
<goals> | ||
<goal>shade</goal> | ||
</goals> | ||
<configuration> | ||
<transformers> | ||
<transformer | ||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> | ||
<mainClass>org.eclipse.passage.releng.maven.CompletePom</mainClass> | ||
</transformer> | ||
</transformers> | ||
<filters> | ||
<filter> | ||
<artifact>*:*</artifact> | ||
<excludes> | ||
<exclude>META-INF/*.SF</exclude> | ||
<exclude>META-INF/*.DSA</exclude> | ||
<exclude>META-INF/*.RSA</exclude> | ||
</excludes> | ||
</filter> | ||
</filters> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
223 changes: 223 additions & 0 deletions
223
releng/org.eclipse.passage.releng/src/org/eclipse/passage/releng/maven/CompletePom.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2021 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* https://www.eclipse.org/legal/epl-2.0/. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.releng.maven; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileOutputStream; | ||
import java.io.FileReader; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.PrintStream; | ||
import java.net.URL; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Calendar; | ||
|
||
import org.apache.maven.model.Developer; | ||
import org.apache.maven.model.License; | ||
import org.apache.maven.model.Model; | ||
import org.apache.maven.model.Scm; | ||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | ||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; | ||
import org.eclipse.jdt.annotation.NonNull; | ||
import org.kohsuke.args4j.CmdLineException; | ||
import org.kohsuke.args4j.CmdLineParser; | ||
import org.kohsuke.args4j.Option; | ||
|
||
public final class CompletePom { | ||
|
||
public static void main(String[] args) { | ||
CompletePom instance = new CompletePom(); | ||
CmdLineParser parser = new CmdLineParser(instance); | ||
try { | ||
parser.parseArgument(args); | ||
} catch (CmdLineException e) { | ||
System.err.println(e.getMessage()); | ||
parser.printUsage(System.err); | ||
return; | ||
} | ||
try { | ||
instance.run(); | ||
} catch (IOException e) { | ||
System.err.println(e.getMessage()); | ||
} | ||
} | ||
|
||
@Option(name = "-dir", usage = "Sets the base directory to scan for POM files", required = true) | ||
public void setBase(@NonNull File dir) { | ||
this.base = dir; | ||
} | ||
|
||
@Option(name = "-dry", usage = "When set, files are not modified and result is dumped to sysout") | ||
public void setDry(boolean dryRun) { | ||
this.dry = dryRun; | ||
} | ||
|
||
private final String year; | ||
private File base; | ||
private boolean dry; | ||
|
||
public CompletePom() { | ||
this.year = String.valueOf(Calendar.getInstance().get(Calendar.YEAR)); | ||
} | ||
|
||
public void run() throws IOException { | ||
System.out.println("Making POMs compliant for Maven Central."); //$NON-NLS-1$ | ||
System.out.println("Processing *.pom files in " + base.getAbsolutePath() + "..."); //$NON-NLS-1$ //$NON-NLS-2$ | ||
Files.find(base.toPath(), 20, (path, basicFileAttributes) -> path.toFile().getPath().endsWith(".pom")) //$NON-NLS-1$ | ||
.forEach(path -> enhancePOMFile(path)); | ||
System.out.println("Done."); //$NON-NLS-1$ | ||
} | ||
|
||
private void enhancePOMFile(Path path) { | ||
boolean modified = false; | ||
Model model = load(path.toFile()); | ||
|
||
if (model.getName() == null) { | ||
model.setName(model.getArtifactId()); | ||
modified = true; | ||
} | ||
|
||
if (model.getUrl() == null) { | ||
model.setUrl("https://www.eclipse.org/passage"); //$NON-NLS-1$ | ||
modified = true; | ||
} | ||
|
||
if (model.getLicenses().isEmpty()) { | ||
License license = new License(); | ||
license.setName("The Eclipse Public License Version 2.0"); //$NON-NLS-1$ | ||
license.setUrl("https://www.eclipse.org/legal/epl-v20.html"); //$NON-NLS-1$ | ||
license.setDistribution("repo"); //$NON-NLS-1$ | ||
model.addLicense(license); | ||
modified = true; | ||
} | ||
|
||
if (model.getScm() == null) { | ||
Scm scm = new Scm(); | ||
scm.setUrl("https://github.com/eclipse-passage/passage.git"); //$NON-NLS-1$ | ||
scm.setConnection("[email protected]:eclipse-passage/passage.git"); //$NON-NLS-1$ | ||
model.setScm(scm); | ||
modified = true; | ||
} | ||
|
||
if (model.getDevelopers().isEmpty()) { | ||
Developer developer = new Developer(); | ||
developer.setId("eclipse"); //$NON-NLS-1$ | ||
developer.setName("Eclipse.org"); //$NON-NLS-1$ | ||
developer.setEmail("[email protected]"); //$NON-NLS-1$ | ||
model.addDeveloper(developer); | ||
modified = true; | ||
} | ||
String groupID = model.getGroupId(); | ||
String artifactID = model.getArtifactId(); | ||
String version = model.getVersion(); | ||
String description = model.getDescription(); | ||
|
||
boolean exists = exists(groupID, artifactID, version); | ||
|
||
if (modified || dry) { | ||
if (modified) { | ||
System.out.println("--------------- Modified: " + path + " exists: " + exists); //$NON-NLS-1$ //$NON-NLS-2$ | ||
} else { | ||
System.out.println("--------------- Unmodified: " + path + " exists " + exists); //$NON-NLS-1$ //$NON-NLS-2$ | ||
} | ||
save(model, path.toFile()); | ||
if (!exists) { | ||
String pomFileName = path.getFileName().toString(); | ||
Path publish = path.getParent().resolve(pomFileName.substring(0, pomFileName.length() - 3) + "publish"); //$NON-NLS-1$ | ||
String title = getJavadocWindowTitle(description, version); | ||
String footer = getJavadocFooter(); | ||
savePublish(publish.toFile(), title, footer); | ||
} | ||
System.out.println(); | ||
} | ||
} | ||
|
||
protected String getJavadocWindowTitle(String string, String version) { | ||
return string + " " + version.substring(0, version.lastIndexOf('.')) + " API Specification"; //$NON-NLS-1$ //$NON-NLS-2$ | ||
} | ||
|
||
protected String getJavadocFooter() { | ||
String product = "Passage"; //$NON-NLS-1$ | ||
return "<font size=\"-1\">Copyright © 2018, " + year //$NON-NLS-1$ | ||
+ "ArSysOp and others" //$NON-NLS-1$ | ||
+ ". Licensed under the <a href=\"https://www.eclipse.org/legal/epl-2.0/\">Eclipse Public License v2.0</a>. All rights reserved.<br/><a href=\"https://bugs.eclipse.org/bugs/enter_bug.cgi?product=" //$NON-NLS-1$ | ||
+ product + "\">Submit a bug or feature</a><br/></font>"; //$NON-NLS-1$ | ||
} | ||
|
||
protected Model load(File file) { | ||
try (FileReader reader = new FileReader(file)) { | ||
return new MavenXpp3Reader().read(reader); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
protected void save(Model model, File target) { | ||
MavenXpp3Writer writer = new MavenXpp3Writer(); | ||
try { | ||
if (dry) { | ||
writer.write(System.out, model); | ||
} else { | ||
try (FileWriter fw = new FileWriter(target)) { | ||
writer.write(fw, model); | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
protected void savePublish(File target, String javadocWindowTitle, String javadocFooter) { | ||
try { | ||
if (dry) { | ||
System.out.println(javadocWindowTitle); | ||
System.out.println(javadocFooter); | ||
} else { | ||
try (FileOutputStream fos = new FileOutputStream(target)) { | ||
PrintStream out = new PrintStream(fos, false, StandardCharsets.UTF_8); | ||
out.println(javadocWindowTitle); | ||
out.println(javadocFooter); | ||
} | ||
} | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
protected boolean exists(String groupID, String artifactID, String version) { | ||
String spec = String.format( | ||
"https://oss.sonatype.org/service/local/lucene/search?g=%s&a=%s&v=%s&repositoryId=releases", // //$NON-NLS-1$ | ||
groupID, artifactID, version); | ||
try { | ||
URL url = new URL(spec); | ||
try (InputStream in = url.openStream(); | ||
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))) { | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
if (line.contains("<totalCount>")) { //$NON-NLS-1$ | ||
return !line.contains("<totalCount>0</totalCount>"); //$NON-NLS-1$ | ||
} | ||
} | ||
} | ||
} catch (IOException ex) { | ||
// well, it does not exist for whatever reason | ||
} | ||
return false; | ||
} | ||
|
||
} |