forked from eclipse-tycho/tycho
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue eclipse-tycho#611 Support setting CI-Friendly-Versions in
tycho-build-extension Add a first implementation and integration test
- Loading branch information
Showing
23 changed files
with
466 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
tycho-build/src/main/java/org/eclipse/tycho/build/DefaultBuildTimestampProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012, 2016 Sonatype Inc. and others. | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Sonatype Inc. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.build; | ||
|
||
import java.util.Date; | ||
|
||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.plugin.MojoExecution; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.component.annotations.Component; | ||
|
||
/** | ||
* Build timestamp provider that returns the same timestamp for all projects, the | ||
* ${maven.build.timestamp}. | ||
*/ | ||
@Component(role = BuildTimestampProvider.class, hint = DefaultBuildTimestampProvider.ROLE_HINT) | ||
public class DefaultBuildTimestampProvider implements BuildTimestampProvider { | ||
|
||
static final String ROLE_HINT = "default"; | ||
|
||
@Override | ||
public Date getTimestamp(MavenSession session, MavenProject project, MojoExecution execution) { | ||
return session.getStartTime(); | ||
} | ||
} |
140 changes: 140 additions & 0 deletions
140
tycho-build/src/main/java/org/eclipse/tycho/build/TychoCiFriendlyVersions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2022 Christoph Läubrich and others. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Christoph Läubrich - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.tycho.build; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
import java.util.TimeZone; | ||
|
||
import javax.annotation.Priority; | ||
import javax.inject.Inject; | ||
import javax.inject.Named; | ||
|
||
import org.apache.maven.execution.DefaultMavenExecutionRequest; | ||
import org.apache.maven.execution.DefaultMavenExecutionResult; | ||
import org.apache.maven.execution.MavenSession; | ||
import org.apache.maven.model.building.ModelBuildingRequest; | ||
import org.apache.maven.model.interpolation.DefaultModelVersionProcessor; | ||
import org.apache.maven.model.interpolation.ModelVersionProcessor; | ||
import org.apache.maven.model.io.DefaultModelReader; | ||
import org.apache.maven.plugin.LegacySupport; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.project.MavenProject; | ||
import org.codehaus.plexus.PlexusContainer; | ||
import org.codehaus.plexus.component.repository.exception.ComponentLookupException; | ||
import org.codehaus.plexus.logging.Logger; | ||
|
||
@Priority(100) | ||
@Named | ||
public class TychoCiFriendlyVersions extends DefaultModelVersionProcessor implements ModelVersionProcessor { | ||
|
||
static final String BUILD_QUALIFIER = "qualifier"; | ||
static final String MICRO_VERSION = "micro"; | ||
static final String MINOR_VERSION = "minor"; | ||
static final String MAJOR_VERSION = "major"; | ||
static final String RELEASE_VERSION = "releaseVersion"; | ||
private PlexusContainer container; | ||
private Logger logger; | ||
|
||
@Inject | ||
public TychoCiFriendlyVersions(PlexusContainer plexusContainer, Logger logger) { | ||
this.container = plexusContainer; | ||
this.logger = logger; | ||
|
||
} | ||
|
||
@Override | ||
public boolean isValidProperty(String property) { | ||
return super.isValidProperty(property) || MAJOR_VERSION.equals(property) || MINOR_VERSION.equals(property) | ||
|| MICRO_VERSION.equals(property) || BUILD_QUALIFIER.equals(property) | ||
|| RELEASE_VERSION.equals(property); | ||
} | ||
|
||
@Override | ||
public void overwriteModelProperties(Properties modelProperties, ModelBuildingRequest request) { | ||
super.overwriteModelProperties(modelProperties, request); | ||
if (request.getSystemProperties().containsKey(MAJOR_VERSION)) { | ||
modelProperties.put(MAJOR_VERSION, request.getSystemProperties().get(MAJOR_VERSION)); | ||
} | ||
if (request.getSystemProperties().containsKey(MINOR_VERSION)) { | ||
modelProperties.put(MINOR_VERSION, request.getSystemProperties().get(MINOR_VERSION)); | ||
} | ||
if (request.getSystemProperties().containsKey(MICRO_VERSION)) { | ||
modelProperties.put(MICRO_VERSION, request.getSystemProperties().get(MICRO_VERSION)); | ||
} | ||
if (request.getSystemProperties().containsKey(BUILD_QUALIFIER)) { | ||
modelProperties.put(BUILD_QUALIFIER, request.getSystemProperties().get(BUILD_QUALIFIER)); | ||
} else { | ||
String formatString = request.getSystemProperties().getProperty("tycho.buildqualifier.format"); | ||
if (formatString != null) { | ||
Date startTime = request.getBuildStartTime(); | ||
File pomFile = request.getPomFile(); | ||
if (startTime != null && pomFile != null) { | ||
String provider = request.getSystemProperties().getProperty("tycho.buildqualifier.provider", | ||
"default"); | ||
try { | ||
BuildTimestampProvider timestampProvider = container.lookup(BuildTimestampProvider.class, | ||
provider); | ||
SimpleDateFormat format = new SimpleDateFormat(formatString); | ||
format.setTimeZone(TimeZone.getTimeZone("UTC")); | ||
Date timestamp = timestampProvider.getTimestamp(getMavenSession(request), | ||
getMavenProject(request), null); | ||
String qualifier = format.format(timestamp); | ||
modelProperties.put(BUILD_QUALIFIER, "." + qualifier); | ||
} catch (ComponentLookupException | MojoExecutionException e) { | ||
logger.warn("Can't use '" + provider | ||
+ "' as a timestamp provider for tycho-ci-friendly-versions (" + e + ")"); | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
private MavenProject getMavenProject(ModelBuildingRequest request) { | ||
// at this phase there are no projects, thats all we can offer for now... | ||
MavenProject mavenProject = new MavenProject(); | ||
DefaultModelReader modelReader = new DefaultModelReader(); | ||
try { | ||
mavenProject.setModel(modelReader.read(request.getPomFile(), Map.of())); | ||
} catch (IOException e) { | ||
// nothing to do here then... | ||
} | ||
mavenProject.setFile(request.getPomFile()); | ||
return mavenProject; | ||
} | ||
|
||
private MavenSession getMavenSession(ModelBuildingRequest request) { | ||
try { | ||
LegacySupport legacySupport = container.lookup(LegacySupport.class); | ||
MavenSession session = legacySupport.getSession(); | ||
if (session != null) { | ||
return session; | ||
} | ||
} catch (ComponentLookupException e) { | ||
// fall through | ||
} | ||
// create a dummy session... actually time providers are not really interested | ||
// in *all* but very limited details | ||
DefaultMavenExecutionRequest executionRequest = new DefaultMavenExecutionRequest(); | ||
executionRequest.setBaseDirectory(request.getPomFile().getParentFile()); | ||
executionRequest.setStartTime(request.getBuildStartTime()); | ||
return new MavenSession(container, executionRequest, new DefaultMavenExecutionResult(), | ||
Collections.emptyList()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.