From 197f88b0fd48c76649961ccd9bb654a17fab461d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Thu, 29 Apr 2021 08:51:11 +0200 Subject: [PATCH] #37 - parse junit version and provide a dedicated container entry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christoph Läubrich --- ...ntry.java => ClasspathContainerEntry.java} | 3 +- .../core/dotClasspath/ClasspathParser.java | 44 +++++++++- .../JUnitClasspathContainerEntry.java | 84 +++++++++++++++++++ 3 files changed, 127 insertions(+), 4 deletions(-) rename tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/{ContainerClasspathEntry.java => ClasspathContainerEntry.java} (88%) create mode 100644 tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/JUnitClasspathContainerEntry.java diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/ContainerClasspathEntry.java b/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/ClasspathContainerEntry.java similarity index 88% rename from tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/ContainerClasspathEntry.java rename to tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/ClasspathContainerEntry.java index 82a4bff8df..429f732ebe 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/ContainerClasspathEntry.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/ClasspathContainerEntry.java @@ -21,11 +21,10 @@ * * */ -public interface ContainerClasspathEntry extends ProjectClasspathEntry { +public interface ClasspathContainerEntry extends ProjectClasspathEntry { static final String JRE_CONTAINER_PATH_PREFIX = "org.eclipse.jdt.launching.JRE_CONTAINER/"; static final String USER_LIBRARY_PATH_PREFIX = "org.eclipse.jdt.USER_LIBRARY/"; - static final String JUNIT_CONTAINER_PATH_PREFIX = "org.eclipse.jdt.junit.JUNIT_CONTAINER/"; /** * diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/ClasspathParser.java b/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/ClasspathParser.java index 22cf4208e7..2ccbde8876 100644 --- a/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/ClasspathParser.java +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/ClasspathParser.java @@ -13,6 +13,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -26,6 +27,7 @@ import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.personality.plexus.lifecycle.phase.Disposable; +import org.eclipse.tycho.ArtifactKey; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; @@ -92,7 +94,13 @@ public synchronized Collection getEntries() throws IOExce new File(file.getParentFile(), output), attributes)); } else if ("con".equals(kind)) { String path = classpathentry.getAttribute("path"); - list.add(new JDTContainerClasspathEntry(path, attributes)); + if (path.startsWith(JUnitClasspathContainerEntry.JUNIT_CONTAINER_PATH_PREFIX)) { + String junit = path + .substring(JUnitClasspathContainerEntry.JUNIT_CONTAINER_PATH_PREFIX.length()); + list.add(new JDTJUnitContainerClasspathEntry(path, junit, attributes)); + } else { + list.add(new JDTContainerClasspathEntry(path, attributes)); + } } } entries = Collections.unmodifiableList(list); @@ -118,7 +126,39 @@ private Map getAttributes(Element parent) { } - private static final class JDTContainerClasspathEntry implements ContainerClasspathEntry { + private static class JDTJUnitContainerClasspathEntry extends JDTContainerClasspathEntry + implements JUnitClasspathContainerEntry { + + private String junit; + + public JDTJUnitContainerClasspathEntry(String path, String junit, Map attributes) { + super(path, attributes); + } + + @Override + public String getJUnitSegment() { + return junit; + } + + @Override + public Collection getArtifacts() { + if (JUNIT3.equals(junit)) { + return Arrays.asList(JUNIT3_PLUGIN); + } else if (JUNIT4.equals(junit)) { + return Arrays.asList(JUNIT4_PLUGIN, HAMCREST_CORE_PLUGIN); + } else if (JUNIT5.equals(junit)) { + return Arrays.asList(JUNIT_JUPITER_API_PLUGIN, JUNIT_JUPITER_ENGINE_PLUGIN, + JUNIT_JUPITER_MIGRATIONSUPPORT_PLUGIN, JUNIT_JUPITER_PARAMS_PLUGIN, + JUNIT_PLATFORM_COMMONS_PLUGIN, JUNIT_PLATFORM_ENGINE_PLUGIN, JUNIT_PLATFORM_LAUNCHER_PLUGIN, + JUNIT_PLATFORM_RUNNER_PLUGIN, JUNIT_PLATFORM_SUITE_API_PLUGIN, JUNIT_VINTAGE_ENGINE_PLUGIN, + JUNIT_OPENTEST4J_PLUGIN, JUNIT_APIGUARDIAN_PLUGIN, JUNIT4_PLUGIN, HAMCREST_CORE_PLUGIN); + } + return Collections.emptyList(); + } + + } + + private static class JDTContainerClasspathEntry implements ClasspathContainerEntry { private String path; private Map attributes; diff --git a/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/JUnitClasspathContainerEntry.java b/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/JUnitClasspathContainerEntry.java new file mode 100644 index 0000000000..725a9b7c5c --- /dev/null +++ b/tycho-core/src/main/java/org/eclipse/tycho/core/dotClasspath/JUnitClasspathContainerEntry.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2021 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Christoph Läubrich - initial API and implementation + *******************************************************************************/ +package org.eclipse.tycho.core.dotClasspath; + +import java.util.Collection; + +import org.eclipse.tycho.ArtifactKey; +import org.eclipse.tycho.ArtifactType; +import org.eclipse.tycho.DefaultArtifactKey; + +public interface JUnitClasspathContainerEntry extends ClasspathContainerEntry { + + static final String JUNIT_CONTAINER_PATH_PREFIX = "org.eclipse.jdt.junit.JUNIT_CONTAINER/"; + + static final String JUNIT3 = "3"; + static final String JUNIT4 = "4"; + static final String JUNIT5 = "5"; + + static final ArtifactKey JUNIT3_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, "org.junit", + "[3.8.2,3.9)"); + + static final ArtifactKey JUNIT4_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, "org.junit", + "[4.13.0,5.0.0)"); + + static final ArtifactKey HAMCREST_CORE_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.hamcrest.core", "[1.1.0,2.0.0)"); + + static final ArtifactKey JUNIT_JUPITER_API_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.junit.jupiter.api", "[5.0.0,6.0.0)"); + + static final ArtifactKey JUNIT_JUPITER_ENGINE_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.junit.jupiter.engine", "[5.0.0,6.0.0)"); + + static final ArtifactKey JUNIT_JUPITER_MIGRATIONSUPPORT_PLUGIN = new DefaultArtifactKey( + ArtifactType.TYPE_INSTALLABLE_UNIT, "org.junit.jupiter.migrationsupport", "[5.0.0,6.0.0)"); + + static final ArtifactKey JUNIT_JUPITER_PARAMS_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.junit.jupiter.params", "[5.0.0,6.0.0)"); + + static final ArtifactKey JUNIT_PLATFORM_COMMONS_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.junit.platform.commons", "[1.0.0,2.0.0)"); + + static final ArtifactKey JUNIT_PLATFORM_ENGINE_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.junit.platform.engine", "[1.0.0,2.0.0)"); + + static final ArtifactKey JUNIT_PLATFORM_LAUNCHER_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.junit.platform.launcher", "[1.0.0,2.0.0)"); + + static final ArtifactKey JUNIT_PLATFORM_RUNNER_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.junit.platform.runner", "[1.0.0,2.0.0)"); + + static final ArtifactKey JUNIT_PLATFORM_SUITE_API_PLUGIN = new DefaultArtifactKey( + ArtifactType.TYPE_INSTALLABLE_UNIT, "org.junit.platform.suite.api", "[1.0.0,2.0.0)"); + + static final ArtifactKey JUNIT_VINTAGE_ENGINE_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.junit.vintage.engine", "[4.12.0,6.0.0)"); + + static final ArtifactKey JUNIT_OPENTEST4J_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.opentest4j", "[1.0.0,2.0.0)"); + + static final ArtifactKey JUNIT_APIGUARDIAN_PLUGIN = new DefaultArtifactKey(ArtifactType.TYPE_INSTALLABLE_UNIT, + "org.apiguardian", "[1.0.0,2.0.0)"); + + /** + * + * @return the JUnit part of the path + */ + String getJUnitSegment(); + + /** + * + * @return the list of artifacts that are part of this container + */ + Collection getArtifacts(); + +}