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

#37 - parse junit version and provide a dedicated container entry #100

Merged
merged 1 commit into from
Apr 29, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
* </ul>
*
*/
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/";

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -92,7 +94,13 @@ public synchronized Collection<ProjectClasspathEntry> 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);
Expand All @@ -118,7 +126,39 @@ private Map<String, String> 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<String, String> attributes) {
super(path, attributes);
}

@Override
public String getJUnitSegment() {
return junit;
}

@Override
public Collection<ArtifactKey> 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<String, String> attributes;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ArtifactKey> getArtifacts();

}