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

Pr 3804 #3806

Merged
merged 2 commits into from
May 3, 2024
Merged

Pr 3804 #3806

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
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ public ArtifactKey getArtifactKey(Artifact artifact) {
}

public Optional<EclipseProject> getEclipseProject(MavenProject project) {
File projectFile = new File(project.getBasedir(), ".project");
return getEclipseProject(project.getBasedir());
}

public Optional<EclipseProject> getEclipseProject(File baseDir) {
File projectFile = new File(baseDir, ".project");
return eclipseProjectCache.computeIfAbsent(projectFile, file -> {
if (file.isFile()) {
try {
Expand Down Expand Up @@ -273,7 +277,7 @@ public Optional<Processor> getBndTychoProject(MavenProject project) {
* Determine the list of dependencies for a given project as a collection of path items
*
* @param project
* the project to use to determine the dependencies
* the project to use to determine the dependencies
* @return a Collection of pathes describing the project dependencies
* @throws Exception
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
Expand All @@ -25,6 +26,7 @@
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable;
import org.eclipse.tycho.ArtifactType;
import org.eclipse.tycho.MavenArtifactKey;
import org.eclipse.tycho.core.TychoProjectManager;
import org.eclipse.tycho.model.classpath.ClasspathParser;
import org.eclipse.tycho.model.classpath.JUnitBundle;
import org.eclipse.tycho.model.classpath.ProjectClasspathEntry;
Expand All @@ -37,15 +39,23 @@ public class ClasspathReader implements Disposable {
@Requirement
Logger logger;

@Requirement
TychoProjectManager projectManager;

@Override
public void dispose() {
cache.clear();
}

public Collection<ProjectClasspathEntry> parse(File basedir) throws IOException {
return cache.computeIfAbsent(basedir.getCanonicalPath(), f -> {

Path resolvedClasspath = projectManager.getEclipseProject(basedir)
.map(project -> project.getFile(ClasspathParser.CLASSPATH_FILENAME))
.orElse(basedir.toPath().resolve(ClasspathParser.CLASSPATH_FILENAME));

return cache.computeIfAbsent(resolvedClasspath.normalize().toString(), f -> {
try {
return ClasspathParser.parse(basedir);
return ClasspathParser.parse(resolvedClasspath.toFile());
} catch (IOException e) {
logger.warn("Can't read classpath from " + basedir);
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ protected void initModel(Model model, Reader artifactReader, Path artifactFile)
}
List<SourceFolderClasspathEntry> sourceFolders = new ArrayList<SourceFolderClasspathEntry>(1);
List<SourceFolderClasspathEntry> testSourceFolders = new ArrayList<SourceFolderClasspathEntry>(1);
for (ProjectClasspathEntry entry : ClasspathParser.parse(bundleRoot.toFile())) {
for (ProjectClasspathEntry entry : ClasspathParser
.parse(bundleRoot.resolve(ClasspathParser.CLASSPATH_FILENAME).toFile())) {
if (entry instanceof SourceFolderClasspathEntry source) {
if (source.isTest()) {
testSourceFolders.add(source);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>junit5-with-linked-resources</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<!-- A linked file relative to the location of the project -->
<link>
<name>.classpath</name>
<type>1</type>
<locationURI>PROJECT_LOC/linkedresources/.classpath</locationURI>
</link>
<!-- A linked folder relative to the location of the project's parent and defined in a variable -->
<link>
<name>src_test</name>
<type>2</type>
<locationURI>VARIABLE_SELFREF_VIA_PARENT/linkedresources/src_test/</locationURI>
</link>
</linkedResources>
<variableList>
<variable>
<name>VARIABLE_SELFREF_VIA_PARENT</name>
<value>$%7BPARENT-1-PROJECT_LOC%7D/junit5-with-linked-files</value>
</variable>
</variableList>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: junit5-with-linked-resources
Bundle-SymbolicName: junit5.with.linked.resources
Bundle-Version: 1.0.0
Bundle-RequiredExecutionEnvironment: JavaSE-11
Export-Package: bundle.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" output="test" path="src_test">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*******************************************************************************
* Copyright (c) 2021 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 bundle.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

public class AdderTest {

@Test
public void incrementTest() {
Counter counter = new Counter();
counter.increment(1);
counter.increment(3);
assertEquals(4, counter.get());
}

@Test
public void decrementTest() {
assertThrows(IllegalArgumentException.class, () -> {
Counter counter = new Counter();
counter.increment(-1);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*******************************************************************************
* Copyright (c) 2021 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 bundle.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.Test;

public class SubtractorTest {

@Test
public void incrementTest() {
CountDown counter = new CountDown(10);
counter.decrement(1);
counter.decrement(3);
assertEquals(6, counter.get());
}

@Test
public void decrementTest() {
assertThrows(IllegalArgumentException.class, ()->{
CountDown counter = new CountDown(10);
counter.decrement(-1);
});
}

@Test
public void decrementTest2() {
assertThrows(IllegalStateException.class, ()->{
CountDown counter = new CountDown(1);
counter.decrement(5);
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>org.eclipse.tycho.tycho-its.surefire</groupId>
<artifactId>junit5.with.linked.resources</artifactId>
<packaging>eclipse-plugin</packaging>
<version>1.0.0</version>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>surefire-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*******************************************************************************
* Copyright (c) 2021 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 bundle.test;

public class CountDown {

RefMe refFromOtherSourceFolder;

int count;

public CountDown(int initalValue) {
count = initalValue;
}

public void decrement(int x) {
if (x < 0) {
throw new IllegalArgumentException();
}
if (count-x < 0) {
throw new IllegalStateException();
}
count -= x;
}

public int get() {
return count;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2021 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 bundle.test;

public class Counter {

int count;

public void increment(int x) {
if (x < 0) {
throw new IllegalArgumentException();
}
count += x;
}

public int get() {
return count;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************************
* Copyright (c) 2021 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 bundle.test;

public class RefMe extends Counter{

}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public void testJUnit5ContainerWithoutTarget() throws Exception {
verifier.verifyTextInLog("Tests run: 5, Failures: 0, Errors: 0, Skipped: 0");
}

@Test
public void testJUnit5ContainerWithLinkedResources() throws Exception {
Verifier verifier = getVerifier("compiler.junitcontainer/junit5-with-linked-resources", false, true);
verifier.executeGoal("test");
verifier.verifyErrorFreeLog();
verifier.verifyTextInLog("-- in bundle.test.AdderTest");
verifier.verifyTextInLog("-- in bundle.test.SubtractorTest");
verifier.verifyTextInLog("Tests run: 5, Failures: 0, Errors: 0, Skipped: 0");
}

@Test
public void testJUnit4Container() throws Exception {
Verifier verifier = getVerifier("compiler.junitcontainer/junit4-in-bundle", true);
Expand Down
Loading
Loading