|
Lines 1-68
Link Here
|
| 1 |
package org.eclipse.tycho.pomgenerator; |
1 |
package org.eclipse.cbi.mojo; |
| 2 |
|
2 |
|
| 3 |
import java.io.File; |
|
|
| 4 |
import java.io.FileInputStream; |
| 5 |
import java.io.FileOutputStream; |
| 6 |
import java.io.IOException; |
| 7 |
import java.io.InputStream; |
| 8 |
import java.io.OutputStreamWriter; |
| 9 |
import java.io.Writer; |
| 10 |
import java.io.BufferedWriter; |
3 |
import java.io.BufferedWriter; |
|
|
4 |
import java.io.File; |
| 11 |
import java.io.FileWriter; |
5 |
import java.io.FileWriter; |
| 12 |
import java.util.ArrayList; |
6 |
import java.io.IOException; |
| 13 |
import java.util.Collections; |
|
|
| 14 |
import java.util.Iterator; |
| 15 |
import java.util.LinkedHashMap; |
| 16 |
import java.util.LinkedHashSet; |
| 17 |
import java.util.List; |
7 |
import java.util.List; |
| 18 |
import java.util.Map; |
8 |
import java.util.Map; |
| 19 |
import java.util.Map.Entry; |
|
|
| 20 |
import java.util.Set; |
| 21 |
import java.util.StringTokenizer; |
| 22 |
|
9 |
|
| 23 |
import javax.xml.parsers.DocumentBuilderFactory; |
|
|
| 24 |
import javax.xml.parsers.DocumentBuilder; |
10 |
import javax.xml.parsers.DocumentBuilder; |
| 25 |
import org.w3c.dom.Document; |
11 |
import javax.xml.parsers.DocumentBuilderFactory; |
| 26 |
import org.w3c.dom.NodeList; |
|
|
| 27 |
import org.w3c.dom.Node; |
| 28 |
import org.w3c.dom.Element; |
| 29 |
import org.xml.sax.SAXException; |
| 30 |
|
12 |
|
| 31 |
import org.apache.maven.artifact.Artifact; |
|
|
| 32 |
import org.apache.maven.model.Build; |
| 33 |
import org.apache.maven.model.Model; |
| 34 |
import org.apache.maven.model.Parent; |
| 35 |
import org.apache.maven.model.Plugin; |
| 36 |
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; |
| 37 |
import org.apache.maven.model.io.xpp3.MavenXpp3Writer; |
| 38 |
import org.apache.maven.plugin.AbstractMojo; |
13 |
import org.apache.maven.plugin.AbstractMojo; |
| 39 |
import org.apache.maven.plugin.MojoExecutionException; |
14 |
import org.apache.maven.plugin.MojoExecutionException; |
| 40 |
import org.apache.maven.plugin.MojoFailureException; |
15 |
import org.apache.maven.plugin.MojoFailureException; |
| 41 |
import org.apache.maven.project.MavenProject; |
16 |
import org.apache.maven.project.MavenProject; |
| 42 |
import org.codehaus.plexus.util.ReaderFactory; |
17 |
import org.codehaus.plexus.util.IOUtil; |
| 43 |
import org.codehaus.plexus.util.xml.XmlStreamReader; |
|
|
| 44 |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
| 45 |
import org.codehaus.plexus.util.xml.Xpp3DomBuilder; |
| 46 |
import org.codehaus.plexus.util.xml.pull.XmlPullParserException; |
| 47 |
import org.eclipse.osgi.framework.adaptor.FilePath; |
| 48 |
import org.eclipse.osgi.service.resolver.BundleDescription; |
| 49 |
import org.eclipse.osgi.service.resolver.State; |
| 50 |
import org.eclipse.tycho.ArtifactDescriptor; |
| 51 |
import org.eclipse.tycho.ArtifactKey; |
18 |
import org.eclipse.tycho.ArtifactKey; |
|
|
19 |
import org.eclipse.tycho.core.BundleProject; |
| 52 |
import org.eclipse.tycho.core.TychoProject; |
20 |
import org.eclipse.tycho.core.TychoProject; |
| 53 |
import org.eclipse.tycho.core.osgitools.BundleReader; |
|
|
| 54 |
import org.eclipse.tycho.core.osgitools.DefaultArtifactKey; |
| 55 |
import org.eclipse.tycho.core.osgitools.DefaultReactorProject; |
21 |
import org.eclipse.tycho.core.osgitools.DefaultReactorProject; |
| 56 |
import org.eclipse.tycho.core.osgitools.DependencyComputer; |
22 |
import org.eclipse.tycho.core.osgitools.OsgiBundleProject; |
| 57 |
import org.eclipse.tycho.core.osgitools.EquinoxResolver; |
23 |
import org.eclipse.tycho.core.osgitools.project.BuildOutputJar; |
| 58 |
import org.eclipse.tycho.core.osgitools.OsgiManifest; |
24 |
import org.eclipse.tycho.core.osgitools.project.EclipsePluginProject; |
| 59 |
import org.eclipse.tycho.core.osgitools.OsgiManifestParserException; |
25 |
import org.w3c.dom.Document; |
| 60 |
import org.eclipse.tycho.core.osgitools.targetplatform.DefaultTargetPlatform; |
26 |
import org.w3c.dom.Node; |
| 61 |
import org.eclipse.tycho.model.Feature; |
27 |
import org.w3c.dom.NodeList; |
| 62 |
import org.eclipse.tycho.model.FeatureRef; |
|
|
| 63 |
import org.eclipse.tycho.model.PluginRef; |
| 64 |
import org.eclipse.tycho.model.UpdateSite; |
| 65 |
import org.osgi.framework.BundleException; |
| 66 |
|
28 |
|
| 67 |
/** |
29 |
/** |
| 68 |
* @goal generate-api-build-xml |
30 |
* @goal generate-api-build-xml |
|
Lines 79-85
public class GenerateAPIBuildXMLMojo extends AbstractMojo {
Link Here
|
| 79 |
* @readonly |
41 |
* @readonly |
| 80 |
*/ |
42 |
*/ |
| 81 |
protected MavenProject project; |
43 |
protected MavenProject project; |
| 82 |
|
44 |
|
|
|
45 |
/** |
| 46 |
* @parameter expression="${buildQualifier}" |
| 47 |
* @readonly |
| 48 |
*/ |
| 49 |
private String qualifier; |
| 50 |
|
| 83 |
/** |
51 |
/** |
| 84 |
* @component role="org.eclipse.tycho.core.TychoProject" |
52 |
* @component role="org.eclipse.tycho.core.TychoProject" |
| 85 |
*/ |
53 |
*/ |
|
Lines 87-93
public class GenerateAPIBuildXMLMojo extends AbstractMojo {
Link Here
|
| 87 |
|
55 |
|
| 88 |
public void execute() throws MojoExecutionException, MojoFailureException { |
56 |
public void execute() throws MojoExecutionException, MojoFailureException { |
| 89 |
File dotProject = new File(project.getBasedir(), ".project"); |
57 |
File dotProject = new File(project.getBasedir(), ".project"); |
| 90 |
if (!dotProject.exists()) { |
58 |
if (!isRelevantPackaging(project.getPackaging()) || !dotProject.exists()) { |
| 91 |
// no .project |
59 |
// no .project |
| 92 |
project.getProperties().setProperty("eclipserun.skip", "true"); |
60 |
project.getProperties().setProperty("eclipserun.skip", "true"); |
| 93 |
return; |
61 |
return; |
|
Lines 98-103
public class GenerateAPIBuildXMLMojo extends AbstractMojo {
Link Here
|
| 98 |
project.getProperties().setProperty("eclipserun.skip", "true"); |
66 |
project.getProperties().setProperty("eclipserun.skip", "true"); |
| 99 |
} |
67 |
} |
| 100 |
} |
68 |
} |
|
|
69 |
|
| 70 |
private boolean isRelevantPackaging(String packaging) { |
| 71 |
return "eclipse-plugin".equals(packaging)|| "eclipse-test-plugin".equals(packaging); |
| 72 |
} |
| 101 |
|
73 |
|
| 102 |
private boolean dotProjectContainsApiNature(File f){ |
74 |
private boolean dotProjectContainsApiNature(File f){ |
| 103 |
try{ |
75 |
try{ |
|
Lines 123-141
public class GenerateAPIBuildXMLMojo extends AbstractMojo {
Link Here
|
| 123 |
return false; |
95 |
return false; |
| 124 |
} |
96 |
} |
| 125 |
|
97 |
|
| 126 |
private void generateBuildXML(){ |
98 |
private void generateBuildXML() throws MojoExecutionException{ |
|
|
99 |
System.out.println("Generating target/.apibuild.xml"); |
| 100 |
File targetDir = new File(project.getBuild().getDirectory()); |
| 101 |
if (!targetDir.isDirectory()) { |
| 102 |
targetDir.mkdirs(); |
| 103 |
} |
| 104 |
BufferedWriter bw = null; |
| 127 |
try { |
105 |
try { |
| 128 |
System.out.println("Generating .apibuild.xml"); |
106 |
File dotApiBuildXML = new File(targetDir, API_BUILD_XML_FILE); |
| 129 |
File dotApiBuildXML = new File(project.getBasedir(), API_BUILD_XML_FILE); |
107 |
bw = new BufferedWriter(new FileWriter(dotApiBuildXML)); |
| 130 |
BufferedWriter bw = new BufferedWriter(new FileWriter(dotApiBuildXML)); |
|
|
| 131 |
bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
108 |
bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); |
| 132 |
bw.write("<project name=\"apigen\" default=\"apigen\">\n"); |
109 |
bw.write("<project name=\"apigen\" default=\"apigen\">\n"); |
| 133 |
bw.write(" <target name=\"apigen\">\n"); |
110 |
bw.write(" <target name=\"apigen\">\n"); |
| 134 |
bw.write(" <apitooling.apigeneration \n"); |
111 |
bw.write(" <apitooling.apigeneration \n"); |
| 135 |
bw.write(" projectname=\"" + calculateName() + "\"\n"); |
112 |
bw.write(" projectname=\"" + calculateName() + "\"\n"); |
| 136 |
bw.write(" project=\"" + project.getBasedir() + "\"\n"); |
113 |
bw.write(" project=\"" + project.getBasedir() + "\"\n"); |
| 137 |
bw.write(" binary=\"" + project.getBuild().getDirectory() + "\"\n"); |
114 |
bw.write(" binary=\"" + getOutputFoldersAsPath() + "\"\n"); |
| 138 |
bw.write(" target=\"" + project.getBuild().getDirectory() + "/classes\"\n"); |
115 |
bw.write(" target=\"" + targetDir + "\"\n"); |
| 139 |
bw.write(" debug=\"true\"\n"); |
116 |
bw.write(" debug=\"true\"\n"); |
| 140 |
bw.write(" \n"); |
117 |
bw.write(" \n"); |
| 141 |
bw.write(" />\n"); |
118 |
bw.write(" />\n"); |
|
Lines 144-158
public class GenerateAPIBuildXMLMojo extends AbstractMojo {
Link Here
|
| 144 |
bw.flush(); |
121 |
bw.flush(); |
| 145 |
} catch (IOException e) { |
122 |
} catch (IOException e) { |
| 146 |
e.printStackTrace(); |
123 |
e.printStackTrace(); |
|
|
124 |
} finally { |
| 125 |
IOUtil.close(bw); |
| 147 |
} |
126 |
} |
| 148 |
} |
127 |
} |
| 149 |
|
128 |
|
|
|
129 |
private String getOutputFoldersAsPath() throws MojoExecutionException { |
| 130 |
StringBuilder path = new StringBuilder(); |
| 131 |
List<BuildOutputJar> outputJars = getEclipsePluginProject() |
| 132 |
.getOutputJars(); |
| 133 |
for (int i = 0; i < outputJars.size(); i++) { |
| 134 |
if (i > 0) { |
| 135 |
path.append(File.pathSeparator); |
| 136 |
} |
| 137 |
path.append(outputJars.get(i).getOutputDirectory().getAbsolutePath()); |
| 138 |
} |
| 139 |
return path.toString(); |
| 140 |
} |
| 141 |
|
| 142 |
private EclipsePluginProject getEclipsePluginProject() throws MojoExecutionException { |
| 143 |
return ((OsgiBundleProject) getBundleProject()).getEclipsePluginProject(DefaultReactorProject.adapt(project)); |
| 144 |
} |
| 145 |
|
| 146 |
private BundleProject getBundleProject() throws MojoExecutionException { |
| 147 |
TychoProject projectType = projectTypes.get(project.getPackaging()); |
| 148 |
if (!(projectType instanceof BundleProject)) { |
| 149 |
throw new MojoExecutionException("Not a bundle project " + project.toString()); |
| 150 |
} |
| 151 |
return (BundleProject) projectType; |
| 152 |
} |
| 153 |
|
| 150 |
private String calculateName() { |
154 |
private String calculateName() { |
| 151 |
TychoProject projectType = projectTypes.get(project.getPackaging()); |
155 |
TychoProject projectType = projectTypes.get(project.getPackaging()); |
| 152 |
ArtifactKey artifactKey = projectType |
156 |
ArtifactKey artifactKey = projectType |
| 153 |
.getArtifactKey(DefaultReactorProject.adapt(project)); |
157 |
.getArtifactKey(DefaultReactorProject.adapt(project)); |
| 154 |
String symbolicName = artifactKey.getId(); |
158 |
String symbolicName = artifactKey.getId(); |
| 155 |
String version = artifactKey.getVersion(); |
159 |
// see org.eclipse.tycho.buildversion.BuildQualifierMojo |
|
|
160 |
String version = project.getProperties().getProperty( |
| 161 |
"unqualifiedVersion"); |
| 162 |
String qualifier = project.getProperties() |
| 163 |
.getProperty("buildQualifier"); |
| 164 |
if (qualifier != null && qualifier.length() > 0) { |
| 165 |
version = version + "." + qualifier; |
| 166 |
} |
| 156 |
return symbolicName + "_" + version; |
167 |
return symbolicName + "_" + version; |
| 157 |
} |
168 |
} |
| 158 |
} |
169 |
} |
| 159 |
- |
|
|