Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Invoker to Integration test for version-bump-plugin #4076

Merged
merged 1 commit into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions tycho-extras/tycho-version-bump-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,4 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>its</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-invoker-plugin</artifactId>
<configuration>
<goals>
<goal>${project.groupId}:${project.artifactId}:${project.version}:update-target</goal>
</goals>
<properties>
<target>update-target.target</target>
</properties>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,17 @@ public void execute() throws MojoExecutionException, MojoFailureException {
createResolver();
doUpdate();
} catch (Exception e) {
if (e instanceof MojoFailureException mfe) {
throw mfe;
}
if (e instanceof MojoExecutionException mee) {
throw mee;
}
throw new MojoExecutionException("Could not update " + getFileToBeUpdated(), e);
}
}

protected abstract File getFileToBeUpdated();
protected abstract File getFileToBeUpdated() throws MojoExecutionException, MojoFailureException;

protected abstract void doUpdate() throws Exception;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import javax.xml.parsers.ParserConfigurationException;

import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
Expand All @@ -40,6 +41,8 @@
import org.eclipse.tycho.targetplatform.TargetDefinition.InstallableUnitLocation;
import org.eclipse.tycho.targetplatform.TargetDefinition.Unit;
import org.eclipse.tycho.targetplatform.TargetDefinitionFile;
import org.eclipse.tycho.targetplatform.TargetPlatformArtifactResolver;
import org.eclipse.tycho.targetplatform.TargetResolveException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Expand All @@ -58,14 +61,18 @@ public class UpdateTargetMojo extends AbstractUpdateMojo {
private TargetDefinitionVariableResolver varResolver;

@Override
protected void doUpdate() throws IOException, URISyntaxException, ParserConfigurationException, SAXException {
protected void doUpdate() throws IOException, URISyntaxException, ParserConfigurationException, SAXException,
TargetResolveException, MojoFailureException {

File file = getFileToBeUpdated();
getLog().info("Update target file " + file);
Document target;
try (FileInputStream input = new FileInputStream(targetFile)) {
try (FileInputStream input = new FileInputStream(file)) {
target = TargetDefinitionFile.parseDocument(input);
TargetDefinitionFile parsedTarget = TargetDefinitionFile.parse(target, targetFile.getAbsolutePath());
TargetDefinitionFile parsedTarget = TargetDefinitionFile.parse(target, file.getAbsolutePath());
resolutionContext.setEnvironments(Collections.singletonList(TargetEnvironment.getRunningEnvironment()));
resolutionContext.addTargetDefinition(new LatestVersionTarget(parsedTarget, varResolver));
resolutionContext.setIgnoreLocalArtifacts(true);
P2ResolutionResult result = p2.getTargetPlatformAsResolutionResult(resolutionContext, executionEnvironment);

Map<String, String> ius = new HashMap<>();
Expand All @@ -85,14 +92,22 @@ protected void doUpdate() throws IOException, URISyntaxException, ParserConfigur
}
}
}
try (FileOutputStream outputStream = new FileOutputStream(targetFile)) {
try (FileOutputStream outputStream = new FileOutputStream(file)) {
TargetDefinitionFile.writeDocument(target, outputStream);
}
}

@Override
protected File getFileToBeUpdated() {
return targetFile;
protected File getFileToBeUpdated() throws MojoFailureException {
if (targetFile == null) {
try {
return TargetPlatformArtifactResolver.getMainTargetFile(project);
} catch (TargetResolveException e) {
throw new MojoFailureException(e);
}
} else {
return targetFile;
}
}

private static final class LatestVersionTarget implements TargetDefinition {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,7 @@
<artifactId>update-target</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-target-definition</packaging>

<pluginRepositories>
<pluginRepository>
<id>tycho-snapshots</id>
<url>${tycho-snapshots-url}</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>


<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.6"?>
<target name="update-target-bug" sequenceNumber="1">
<locations>
<location includeAllPlatforms="false" includeMode="slicer"
includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.equinox.executable.feature.group"
version="0.0.0" />
<unit id="org.eclipse.jdt.feature.group" version="0.0.0" />
<unit id="org.eclipse.platform.ide" version="0.0.0" />
<unit id="org.eclipse.pde.feature.group" version="0.0.0" />
<repository
location="https://download.eclipse.org/eclipse/updates/4.17/" />
</location>
</locations>
</target>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*******************************************************************************
* Copyright (c) 2024 Christoph Läubrich 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:
* Christoph Läubrich - initial API and implementation
*******************************************************************************/
package org.eclipse.tycho.test;

import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.maven.it.Verifier;
import org.eclipse.tycho.targetplatform.TargetDefinition.InstallableUnitLocation;
import org.eclipse.tycho.targetplatform.TargetDefinition.Location;
import org.eclipse.tycho.targetplatform.TargetDefinition.Unit;
import org.eclipse.tycho.targetplatform.TargetDefinitionFile;
import org.eclipse.tycho.version.TychoVersion;
import org.junit.Test;
import org.w3c.dom.Document;

public class VersionBumpPluginTest extends AbstractTychoIntegrationTest {

@Test
public void testUpdateTarget() throws Exception {
Verifier verifier = getVerifier("tycho-version-bump-plugin/update-target", false, true);
String sourceTargetFile = "update-target.target";
verifier.setSystemProperty("target", sourceTargetFile);
verifier.setSystemProperty("tycho.localArtifacts", "ignore");
verifier.executeGoal("org.eclipse.tycho.extras:tycho-version-bump-plugin:" + TychoVersion.getTychoVersion()
+ ":update-target");
verifier.verifyErrorFreeLog();
File targetFile = new File(verifier.getBasedir(), sourceTargetFile);
try (FileInputStream input = new FileInputStream(targetFile)) {
Document target = TargetDefinitionFile.parseDocument(input);
TargetDefinitionFile parsedTarget = TargetDefinitionFile.parse(target, targetFile.getAbsolutePath());
List<? extends Location> locations = parsedTarget.getLocations();
InstallableUnitLocation iu = locations.stream().filter(InstallableUnitLocation.class::isInstance)
.map(InstallableUnitLocation.class::cast).findFirst()
.orElseThrow(() -> new AssertionError("IU Location not found!"));
List<? extends Unit> units = iu.getUnits();
assertEquals(4, units.size());
assertIUVersion("org.eclipse.equinox.executable.feature.group", "3.8.900.v20200819-0940", units,
targetFile);
assertIUVersion("org.eclipse.jdt.feature.group", "3.18.500.v20200902-1800", units, targetFile);
assertIUVersion("org.eclipse.platform.ide", "4.17.0.I20200902-1800", units, targetFile);
assertIUVersion("org.eclipse.pde.feature.group", "3.14.500.v20200902-1800", units, targetFile);
}
}

private void assertIUVersion(String id, String version, List<? extends Unit> units, File targetFile) {
for (Unit unit : units) {
if (unit.getId().equals(id) && unit.getVersion().equals(version)) {
return;
}
}
fail("Unit with id " + id + " and version " + version + " not found: "
+ units.stream().map(String::valueOf).collect(Collectors.joining(System.lineSeparator()))
+ " in target file " + targetFile);

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,11 @@ public String getVersion() {
return version;
}

@Override
public String toString() {
return "Unit [id=" + id + ", version=" + version + "]";
}

}

private TargetDefinitionFile(Document document, String origin) throws TargetDefinitionSyntaxException {
Expand Down
Loading