Search in sources :

Example 6 with OsgiManifest

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;
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Resource(org.apache.maven.model.Resource) OsgiManifest(org.eclipse.tycho.core.osgitools.OsgiManifest) IOException(java.io.IOException) BuildProperties(org.eclipse.tycho.core.shared.BuildProperties) Properties(java.util.Properties) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 7 with OsgiManifest

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());
}
Also used : DefaultBundleReader(org.eclipse.tycho.core.osgitools.DefaultBundleReader) OsgiManifest(org.eclipse.tycho.core.osgitools.OsgiManifest) Verifier(org.apache.maven.it.Verifier) FileFilter(java.io.FileFilter) File(java.io.File) Test(org.junit.Test) AbstractTychoIntegrationTest(org.eclipse.tycho.test.AbstractTychoIntegrationTest)

Example 8 with OsgiManifest

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);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArtifactDescriptor(org.eclipse.tycho.ArtifactDescriptor) ArrayList(java.util.ArrayList) Model(org.apache.maven.model.Model) OsgiManifest(org.eclipse.tycho.core.osgitools.OsgiManifest) File(java.io.File)

Aggregations

OsgiManifest (org.eclipse.tycho.core.osgitools.OsgiManifest)8 File (java.io.File)7 FileOutputStream (java.io.FileOutputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 ArtifactDescriptor (org.eclipse.tycho.ArtifactDescriptor)2 ArtifactKey (org.eclipse.tycho.ArtifactKey)2 FileFilter (java.io.FileFilter)1 OutputStream (java.io.OutputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 JarFile (java.util.jar.JarFile)1 Verifier (org.apache.maven.it.Verifier)1 Model (org.apache.maven.model.Model)1 Resource (org.apache.maven.model.Resource)1 BundleStartLevel (org.eclipse.sisu.equinox.launching.BundleStartLevel)1 DefaultArtifactKey (org.eclipse.tycho.DefaultArtifactKey)1 DefaultBundleReader (org.eclipse.tycho.core.osgitools.DefaultBundleReader)1