use of org.eclipse.tycho.core.osgitools.OsgiManifest in project tycho by eclipse.
the class OsgiSourceMojo method generateL10nFile.
private Resource generateL10nFile() throws MojoExecutionException {
OsgiManifest origManifest = bundleReader.loadManifest(project.getBasedir());
Properties l10nProps = readL10nProps(origManifest);
String bundleName = getL10nResolvedValue(origManifest, BUNDLE_NAME, l10nProps);
if (bundleName == null) {
getLog().warn("Bundle-Name header not found in " + new File(project.getBasedir(), JarFile.MANIFEST_NAME) + ", fallback to Bundle-SymbolicName for source bundle");
bundleName = origManifest.getBundleSymbolicName();
}
String sourceBundleName = bundleName + " Source";
String bundleVendor = getL10nResolvedValue(origManifest, BUNDLE_VENDOR, l10nProps);
if (bundleVendor == null) {
getLog().warn("Bundle-Vendor header not found in " + new File(project.getBasedir(), JarFile.MANIFEST_NAME) + ", fallback to 'unknown' for source bundle");
bundleVendor = "unknown";
}
File l10nOutputDir = new File(project.getBuild().getDirectory(), "sourcebundle-l10n-gen");
Properties sourceL10nProps = new Properties();
sourceL10nProps.setProperty(I18N_KEY_BUNDLE_NAME, sourceBundleName);
sourceL10nProps.setProperty(I18N_KEY_BUNDLE_VENDOR, bundleVendor);
File l10nPropsFile = new File(l10nOutputDir, MANIFEST_BUNDLE_LOCALIZATION_FILENAME);
l10nPropsFile.getParentFile().mkdirs();
OutputStream out = null;
try {
out = new FileOutputStream(l10nPropsFile);
sourceL10nProps.store(out, "Source Bundle Localization");
} catch (IOException e) {
throw new MojoExecutionException("error while generating source bundle localization file", e);
} finally {
IOUtil.close(out);
}
Resource l10nResource = new Resource();
l10nResource.setDirectory(l10nOutputDir.getAbsolutePath());
l10nResource.setIncludes(singletonList(MANIFEST_BUNDLE_LOCALIZATION_FILENAME));
return l10nResource;
}
use of org.eclipse.tycho.core.osgitools.OsgiManifest in project tycho by eclipse.
the class JarDirectoryBundlesTest method test.
@Test
public void test() throws Exception {
Verifier verifier = getVerifier("MNGECLIPSE949jarDirectoryBundles");
verifier.executeGoal("package");
verifier.verifyErrorFreeLog();
File[] sitePlugins = new File(verifier.getBasedir(), "site/target/site/plugins").listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isFile() && pathname.getName().startsWith("org.eclipse.platform") && pathname.getName().endsWith(".jar");
}
});
Assert.assertEquals(1, sitePlugins.length);
// verify the bundle actually makes sense
DefaultBundleReader reader = new DefaultBundleReader();
OsgiManifest siteBundleManifest = reader.loadManifest(sitePlugins[0]);
Assert.assertEquals("platform.jar", siteBundleManifest.getBundleClasspath()[0]);
Assert.assertEquals("org.eclipse.platform", siteBundleManifest.getBundleSymbolicName());
File[] productPlugins = new File(verifier.getBasedir(), "product/target/product/eclipse/plugins").listFiles(new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.isDirectory() && pathname.getName().startsWith("org.eclipse.platform");
}
});
Assert.assertEquals(1, productPlugins.length);
// verify directory actually makes sense
OsgiManifest productBundleManifest = reader.loadManifest(productPlugins[0]);
Assert.assertEquals("platform.jar", productBundleManifest.getBundleClasspath()[0]);
Assert.assertEquals("org.eclipse.platform", productBundleManifest.getBundleSymbolicName());
}
use of org.eclipse.tycho.core.osgitools.OsgiManifest in project tycho by eclipse.
the class GeneratePomsMojo method execute.
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
List<File> baseDirs = getBaseDirs();
if (getLog().isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append("baseDir=").append(toString(baseDir)).append('\n');
sb.append("extraDirs=").append(extraDirs).append('\n');
for (int i = 0; i < baseDirs.size(); i++) {
sb.append("dir[").append(i).append("]=").append(toString(baseDirs.get(i))).append('\n');
}
getLog().debug(sb.toString());
}
// find all candidate folders
List<File> candidateDirs = new ArrayList<>();
for (File basedir : baseDirs) {
findAndAddCandidates(candidateDirs, basedir);
}
// find all root projects
List<File> rootProjects = getRootProjects();
if (getLog().isDebugEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append("rootProjects=").append(this.rootProjects);
for (int i = 0; i < rootProjects.size(); i++) {
sb.append("rootProject[").append(i).append("]=").append(toString(rootProjects.get(i))).append('\n');
}
getLog().debug(sb.toString());
}
for (File dir : candidateDirs) {
if (isPluginProject(dir)) {
OsgiManifest mf = bundleReader.loadManifest(dir);
platform.addArtifactFile(mf.toArtifactKey(), dir, null);
}
}
// testSuite
File testSuiteLocation = null;
if (testSuite != null) {
ArtifactDescriptor bundle = platform.getArtifact(ArtifactType.TYPE_ECLIPSE_PLUGIN, testSuite, null);
if (bundle != null) {
testSuiteLocation = bundle.getLocation();
}
}
Set<File> projects = new LinkedHashSet<>();
// always add baseDir
projects.add(baseDirs.get(0));
if (rootProjects.size() > 0) {
if (testSuiteLocation != null) {
rootProjects.add(testSuiteLocation);
}
for (File rootProject : rootProjects) {
getLog().info("Resolving root project " + toString(rootProject));
if (isUpdateSiteProject(rootProject)) {
projects.addAll(getSiteFeaturesAndPlugins(rootProject));
projects.add(rootProject);
} else if (isFeatureProject(rootProject)) {
projects.addAll(getFeatureFeaturesAndPlugins(rootProject));
projects.add(rootProject);
} else if (isPluginProject(rootProject)) {
// TODO getPluginAndDependencies
addPluginImpl(projects, rootProject);
projects.add(rootProject);
} else {
getLog().warn("Unsupported root project " + toString(rootProject));
}
}
} else {
projects.addAll(candidateDirs);
}
if (getLog().isDebugEnabled()) {
getLog().debug("Collected " + projects.size() + " projects");
for (File dir : projects) {
getLog().debug("\t" + toString(dir));
}
}
// write poms
Iterator<File> projectIter = projects.iterator();
File parentDir = projectIter.next();
if (!projectIter.hasNext()) {
if (isProjectDir(parentDir)) {
generatePom(null, parentDir);
} else {
throw new MojoExecutionException("Could not find any valid projects");
}
} else {
Model parent = readPomTemplate("parent-pom.xml");
parent.setGroupId(groupId);
parent.setArtifactId(parentDir.getName());
parent.setVersion(version);
while (projectIter.hasNext()) {
File projectDir = projectIter.next();
generatePom(parent, projectDir);
parent.addModule(getModuleName(parentDir, projectDir));
}
reorderModules(parent, parentDir, testSuiteLocation);
addTychoExtension(parent);
writePom(parentDir, parent);
generateAggregatorPoms(testSuiteLocation);
}
}
Aggregations