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);
}
}
}
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);
}
}
}
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);
}
}
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();
}
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];
}
Aggregations