Search in sources :

Example 6 with PomFile

use of org.eclipse.tycho.versions.pom.PomFile in project tycho by eclipse.

the class ProjectMetadataReader method addBasedir.

public void addBasedir(File basedir) throws IOException {
    if (!basedir.exists()) {
        log.info("Project does not exist at " + basedir);
        return;
    }
    if (basedir.isFile()) {
        if (!PomFile.POM_XML.equals(basedir.getName())) {
            // TODO support custom pom.xml file names
            log.info("Custom pom.xml file name is not supported at " + basedir);
            return;
        }
        basedir = basedir.getParentFile();
    }
    if (projects.containsKey(basedir)) {
        // TODO test me
        return;
    }
    ProjectMetadata project = new ProjectMetadata(basedir);
    projects.put(basedir, project);
    File pomFile = new File(basedir, PomFile.POM_XML);
    if (!pomFile.exists()) {
        pomFile = new File(basedir, PomFile.POLYGLOT_POM_XML);
    }
    if (!pomFile.exists()) {
        log.info("No pom file found at " + basedir);
        return;
    }
    PomFile pom = PomFile.read(pomFile, PomFile.POM_XML.equals(pomFile.getName()));
    project.putMetadata(pom);
    String packaging = pom.getPackaging();
    if (PACKAGING_POM.equals(packaging)) {
        for (File child : getChildren(basedir, pom)) {
            addBasedir(child);
        }
    }
}
Also used : PomFile(org.eclipse.tycho.versions.pom.PomFile) PomFile(org.eclipse.tycho.versions.pom.PomFile) File(java.io.File)

Example 7 with PomFile

use of org.eclipse.tycho.versions.pom.PomFile in project tycho by eclipse.

the class VersionsEngine method apply.

public void apply() throws IOException {
    VersionChangesDescriptor versionChangeContext = new VersionChangesDescriptor(originalVersionChanges, new DefaultVersionRangeUpdateStrategy(updateVersionRangeMatchingBounds));
    // collecting secondary changes
    boolean newChanges = true;
    while (newChanges) {
        newChanges = false;
        for (ProjectMetadata project : projects) {
            for (MetadataManipulator manipulator : manipulators) {
                newChanges |= manipulator.addMoreChanges(project, versionChangeContext);
            }
        }
    }
    // validate version changes can be implemented
    List<String> errors = new ArrayList<>();
    for (ProjectMetadata project : projects) {
        for (MetadataManipulator manipulator : manipulators) {
            Collection<String> error = manipulator.validateChanges(project, versionChangeContext);
            if (error != null) {
                errors.addAll(error);
            }
        }
    }
    if (!errors.isEmpty()) {
        throw new IllegalVersionChangeException(errors);
    }
    // make changes to the metadata
    for (ProjectMetadata project : projects) {
        logger.info("Making changes in " + project.getBasedir().getAbsolutePath());
        PomFile pom = project.getMetadata(PomFile.class);
        // TODO property changes should be added as a new type of change in VersionChangeDescriptors
        for (PropertyChange propertyChange : propertyChanges) {
            if (pom == propertyChange.pom) {
                ((PomManipulator) pomManipulator).applyPropertyChange(pom, propertyChange.propertyName, propertyChange.propertyValue);
            }
        }
        // apply changes
        for (MetadataManipulator manipulator : manipulators) {
            manipulator.applyChanges(project, versionChangeContext);
        }
    }
    // write changes to the disk
    for (ProjectMetadata project : projects) {
        for (MetadataManipulator manipulator : manipulators) {
            manipulator.writeMetadata(project);
        }
    }
}
Also used : PomManipulator(org.eclipse.tycho.versions.manipulation.PomManipulator) ArrayList(java.util.ArrayList) PomFile(org.eclipse.tycho.versions.pom.PomFile)

Example 8 with PomFile

use of org.eclipse.tycho.versions.pom.PomFile in project tycho by eclipse.

the class PomManipulator method writeMetadata.

@Override
public void writeMetadata(ProjectMetadata project) throws IOException {
    PomFile pom = project.getMetadata(PomFile.class);
    File pomFile = new File(project.getBasedir(), "pom.xml");
    if (pom != null && pomFile.exists()) {
        PomFile.write(pom, pomFile);
    }
}
Also used : PomFile(org.eclipse.tycho.versions.pom.PomFile) PomFile(org.eclipse.tycho.versions.pom.PomFile) File(java.io.File)

Example 9 with PomFile

use of org.eclipse.tycho.versions.pom.PomFile in project tycho by eclipse.

the class VersionUpdater method apply.

public void apply() throws IOException {
    for (ProjectMetadata project : projects) {
        PomFile pom = project.getMetadata(PomFile.class);
        if (pom == null) {
            logger.info("Not a maven project " + project.getBasedir());
            continue;
        }
        String pomVersion = Versions.toCanonicalVersion(pom.getVersion());
        VersionAdaptor adaptor = updaters.get(pom.getPackaging());
        if (adaptor != null) {
            String osgiVersion = Versions.toCanonicalVersion(adaptor.getVersion(project, logger));
            if (osgiVersion != null && !Versions.isVersionEquals(pomVersion, osgiVersion)) {
                addVersionChange(engine, pom, osgiVersion);
            }
        }
    }
    engine.apply();
}
Also used : PomFile(org.eclipse.tycho.versions.pom.PomFile)

Example 10 with PomFile

use of org.eclipse.tycho.versions.pom.PomFile in project tycho by eclipse.

the class VersionUpdater method findProductFile.

private static File findProductFile(ProjectMetadata project, PomFile pom, Logger logger) {
    File productFile = new File(project.getBasedir(), pom.getArtifactId() + ".product");
    if (productFile.exists()) {
        return productFile;
    }
    File[] productFiles = project.getBasedir().listFiles(new ProductFileFilter());
    if (productFiles == null || productFiles.length == 0) {
        logger.warn("Skipping updating pom in directory " + project.getBasedir() + " because no product file found to extract the (new) version");
        return null;
    }
    if (productFiles.length > 1) {
        logger.warn("Skipping updating pom in directory " + project.getBasedir() + " because more than one product files have been found. Only one product file is supported or one must be named <artifactId>.product");
        return null;
    }
    return productFiles[0];
}
Also used : PomFile(org.eclipse.tycho.versions.pom.PomFile) File(java.io.File) ProductFileFilter(org.eclipse.tycho.versions.utils.ProductFileFilter)

Aggregations

PomFile (org.eclipse.tycho.versions.pom.PomFile)10 File (java.io.File)4 PomVersionChange (org.eclipse.tycho.versions.engine.PomVersionChange)2 GAV (org.eclipse.tycho.versions.pom.GAV)2 ArtifactCoordinates (com.itemis.maven.aether.ArtifactCoordinates)1 ReleasePhase (com.itemis.maven.plugins.unleash.ReleasePhase)1 ProjectToString (com.itemis.maven.plugins.unleash.util.functions.ProjectToString)1 XMLParseException (de.pdark.decentxml.XMLParseException)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 PomManipulator (org.eclipse.tycho.versions.manipulation.PomManipulator)1 Profile (org.eclipse.tycho.versions.pom.Profile)1 ProductFileFilter (org.eclipse.tycho.versions.utils.ProductFileFilter)1 Test (org.junit.Test)1