Skip to content

Commit

Permalink
the symlinks IT project links to a new project subdirectories
Browse files Browse the repository at this point in the history
This way, the "multisources" project, which was used for targets of
symlinks, does not get deleted.

The "multisources-to-link" is just a copy of "multisources" that is
meant to be used only for targets of the symlinks project.
  • Loading branch information
LorenzoBettini committed Apr 20, 2023
1 parent 7ecc857 commit 31e195c
Show file tree
Hide file tree
Showing 8 changed files with 161 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,7 @@ public class MavenVerifierUtil {
private static File localRepoDir;

public static Verifier newVerifier(String pathToTestProject) throws IOException, VerificationException {
// it's best to pass a subdirectory of the target folder for "maven.test.tmpdir":
// that will be the directory where our IT projects will be copied and where
// the Maven build will be executed.
// This will make their inspection afterward (the log.txt file) easier.
// For this reason, we delete that directory here, but NOT after the tests.
String tempDirPath = System.getProperty("maven.test.tmpdir", System.getProperty("java.io.tmpdir"));
File tempDir = new File(tempDirPath);
File testDir = new File(tempDir, pathToTestProject);
FileUtils.deleteDirectory(testDir);

String localCentralRepository = System.getProperty("maven.repo.local",
System.getProperty("user.home") + "/.m2/repository");
localRepoDir = new File( localCentralRepository );
System.out.println("IT projects will be executed from " + testDir);
System.out.println("Local Maven Central Repository " + localRepoDir);

testDir = ResourceExtractor.extractResourcePath(MavenVerifierUtil.class, pathToTestProject, tempDir, true);
File testDir = extractResourcePath(pathToTestProject);
Verifier verifier = new Verifier(testDir.getAbsolutePath(), true);

String testMavenRepo = System.getProperty("testMavenRepo");
Expand All @@ -64,6 +48,11 @@ public static Verifier newVerifier(String pathToTestProject) throws IOException,
+ "'Run ITs from Eclipse.launch'.",
testMavenRepo);
verifier.setLocalRepo(testMavenRepo);

String localCentralRepository = System.getProperty("maven.repo.local",
System.getProperty("user.home") + "/.m2/repository");
localRepoDir = new File( localCentralRepository );

verifier.setSystemProperty("local-central", localRepoDir.toString());

if (debug) {
Expand All @@ -82,7 +71,22 @@ public static Verifier newVerifier(String pathToTestProject) throws IOException,
return verifier;
}

static public void checkMavenExecutable(String verifierRoot) throws IOException, VerificationException {
public static File extractResourcePath(String pathToTestProject) throws IOException {
// it's best to pass a subdirectory of the target folder for "maven.test.tmpdir":
// that will be the directory where our IT projects will be copied and where
// the Maven build will be executed.
// This will make their inspection afterward (the log.txt file) easier.
// For this reason, we delete that directory here, but NOT after the tests.
String tempDirPath = System.getProperty("maven.test.tmpdir", System.getProperty("java.io.tmpdir"));
File tempDir = new File(tempDirPath);
File testDir = new File(tempDir, pathToTestProject);
FileUtils.deleteDirectory(testDir);

testDir = ResourceExtractor.extractResourcePath(MavenVerifierUtil.class, pathToTestProject, tempDir, true);
return testDir;
}

public static void checkMavenExecutable(String verifierRoot) throws IOException, VerificationException {
File mvnExecutable = new File(new Verifier(verifierRoot).getExecutable());
if (!mvnExecutable.exists()) {
String mavenHome = findMaven();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.apache.maven.it.util.ResourceExtractor;
import org.apache.maven.shared.utils.io.FileUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -210,13 +209,18 @@ public void readXtendPrefsUnused() throws Exception {

@Test
public void readSymlinks() throws Exception {
String root = ResourceExtractor.simpleExtractResources(getClass(), ROOT).getAbsolutePath();
// first copy the project under test
Verifier verifier = MavenVerifierUtil.newVerifier(ROOT + "/symlinks");
// then copy the project containing the target folders for the symlinks
// note we use a project not used in any other tests, so that we won't risk
// to remove the contents of an already tested project
String root = MavenVerifierUtil.extractResourcePath(ROOT + "/multisources-to-link")
.getParent();
File link = new File(root + "/symlinks/src/main/java");
File link2 = new File(root + "/symlinks/src/test/java");
createSymLink(root + "/multisources/src/main/java/", link.getAbsolutePath());
createSymLink(root + "/multisources/src/test/java/", link2.getAbsolutePath());
createSymLink(root + "/multisources-to-link/src/main/java/", link.getAbsolutePath());
createSymLink(root + "/multisources-to-link/src/test/java/", link2.getAbsolutePath());
try {
Verifier verifier = MavenVerifierUtil.newVerifier(ROOT + "/symlinks");
verifier.setDebug(true);
verifier.executeGoal("test");
verifier.verifyErrorFreeLog();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.xtend</groupId>
<artifactId>it-tests-parent</artifactId>
<version>IT-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<artifactId>multisources</artifactId>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src/main/java2</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-test-source</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/test/java2</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package test

class XtendA extends JavaB {

def JavaB test2(XtendC s) {
return s.foo.newJavaB
}

def JavaB newJavaB() {
return new JavaB()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package test

class XtendC {
def JavaB test(XtendA s) {
return null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2011 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package test;

/**
* @author efftinge - Initial contribution and API
*/
public class JavaB extends XtendC {
public XtendA foo(XtendC test) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package foo

import org.junit.Test
import org.junit.Assert
import foo.FooClass

class FooTest {

@Test
def assertTrue() {
Assert::assertEquals(1,new FooClass().count);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package foo

import test.JavaB

class FooClass {

def int count() {
return 1
}

def JavaB newJavaB() {
return new JavaB()
}
}

0 comments on commit 31e195c

Please sign in to comment.