Commit c10332de authored by Daniel Bluhm's avatar Daniel Bluhm

Merge branch 'next' into feature/aes

Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parents 47447d78 5bed7ffc
# The Eclipse Integrated Computational Environment (ICE) Main Repository
Please see [our wiki](https://wiki.eclipse.org/ICE) for detailed information about Eclipse ICE, including where to download binaries.
Please see [the website](https://www.eclipse.org/ice) for more information on the project.
Build instructions are available [on our wiki too](http://wiki.eclipse.org/ICE_Build_Instructions).
## Build Instructions
Contributions follow the standard Eclipse mechanisms and you should check out our [CONTRIBUTING.md](https://github.com/eclipse/ice/blob/master/CONTRIBUTING.md) file for more information. If you are looking at this, then you are most likely using Git and can start the process by issuing
a pull request on our GitHub repo.
Checkout the project and from the org.eclipse.ice.build directory execute
```bash
mvn clean install
```
## Using the project generators
Once the build is complete, use the project generators to get started with a new Eclipse ICE project. From the shell, execute the following for a basic project:
```bash
mvn archetype:generate -DarchetypeGroupId=org.eclipse.ice -DarchetypeArtifactId=data-element-archetype -DarchetypeVersion=1.0-SNAPSHOT -DgroupId=com.test -DartifactId=testApp
```
For a web form project, execute the following
```bash
mvn archetype:generate -DarchetypeGroupId=org.eclipse.ice -DarchetypeArtifactId=data-element-webform-archetype -DarchetypeVersion=1.0-SNAPSHOT -DgroupId=com.test -DartifactId=testApp
```
The group and artifact ids above are examples and should be replaced with the correct ids for your use case.
# Data Element Example
There are a number of examples in the test and org.eclipse.ice.renderer packages. There is also a [gist available](https://code.ornl.gov/snippets/109).
# Commands Examples
Examples for using the Commands tools are available [in the demo bundle](https://github.com/eclipse/ice/tree/next/org.eclipse.ice.demo/src/org/eclipse/ice/demo/commands).
# Getting started on development
If you're using Eclipse for development, you need to install Lombok into the Eclipse environment so that Eclipse knows about the bytecode changes that Lombok makes during the build process. Instructions are available here: https://projectlombok.org/setup/eclipse
Contributions follow the standard Eclipse mechanisms and you should check out our [CONTRIBUTING.md](https://github.com/eclipse/ice/blob/master/CONTRIBUTING.md) file for more information. If you are looking at this, then you are most likely using Git and can start the process by issuing
a pull request on our GitHub repo.
If you're using Eclipse for development, you need to install Lombok into the Eclipse environment so that Eclipse knows about the bytecode changes that Lombok makes during the build process. Instructions are available [at the Lombok site](https://projectlombok.org/setup/eclipse).
Using the project generators
-
# Contacting the development team
Instructions for generating a new project with the maven archeytpes.
pull the org.eclipse.ice.archetypes project
make sure that the data element renderer and annotations projects are built as well
build the package and it should build the archetypes as well.
then you can use mvn archetype:generate -DarchetypeGroupId=org.eclipse.ice -DarchetypeArtifactId=data-element-archetype -DarchetypeVersion=1.0-SNAPSHOT -DgroupId=com.test -DartifactId=testApp
Note* use -DarchetypeArtifactId=data-element-webform-archetype for the webform archetype
replace the group and artifact id's with whatever.
\ No newline at end of file
Please submit a ticket or pull request to contact the team. Alternatively, use the [ice-dev@eclipse.org mailing list](https://accounts.eclipse.org/mailing-list/ice-dev) to post questions.
......@@ -29,6 +29,15 @@
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" 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="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
......@@ -29,5 +24,6 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.ice.dev.dependencyscraper</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>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>org.eclipse.ice.dev</artifactId>
<groupId>org.eclipse.ice</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.ice.dev.dependencyscraper</artifactId>
<packaging>maven-plugin</packaging>
<name>org.eclipse.ice.dev.dependencyscraper Maven Plugin</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<prerequisites>
<maven>${maven.version}</maven>
</prerequisites>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
<maven.version>3.3.9</maven.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>${maven.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-compat</artifactId>
<version>${maven.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-testing</groupId>
<artifactId>maven-plugin-testing-harness</artifactId>
<version>3.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_maven-plugin_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<version>3.1.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<!-- <goalPrefix>maven-archetype-plugin</goalPrefix> -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
<execution>
<id>help-goal</id>
<goals>
<goal>helpmojo</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
/*******************************************************************************
* Copyright (c) 2020- UT-Battelle, LLC.
* 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:
* Daniel Bluhm - Initial implementation
*******************************************************************************/
package org.org.eclipse.ice.dev.dependencyscraper;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import java.util.zip.ZipEntry;
/**
* Maven plugin used to search dependencies for files matching filtering rules
* and copy to output directory.
*/
@Mojo(
name = "scrape",
defaultPhase = LifecyclePhase.PROCESS_SOURCES,
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME
)
public class DependencyScraper extends AbstractMojo {
/**
* Prefix used for generated temp files.
*/
private static final String TEMP_PREFIX = "org.eclipse.ice.dev.dependencyscraper";
/**
* Current project. Used to get handle to dependencies.
*/
@Parameter(
defaultValue = "${project}",
readonly = true,
required = true
)
private MavenProject project;
/**
* Directory to output scraped files.
*/
@Parameter(
property = "outputDirectory",
required = true
)
private File outputDirectory;
@Parameter(
property = "sourceDirectory",
required = true
)
private String sourceDirectory;
/**
* List of files to include. May contain wildcards, i.e. <code>*</code> or
* <code>**{@literal /}*.js</code>.
*/
@Parameter(
property = "includes",
required = true
)
private List<String> includes;
/**
* Whether files should be overwritten if they already exist.
*/
@Parameter(
property = "clobber",
required = false,
defaultValue = "false"
)
private boolean clobber;
/**
* Set of jar files that will be searched for matching files.
*/
private Set<File> jarFiles;
/**
* Setter for outputDirectory.
* @param outputDirectory to set.
*/
public void setOutputDirectory(File outputDirectory) {
this.outputDirectory = outputDirectory;
}
/**
* Setter for includes.
* @param includes to set.
*/
public void setIncludes(List<String> includes) {
this.includes = includes;
}
/**
* Setter for clobber.
* @param clobber to set.
*/
public void setClobber(boolean clobber) {
this.clobber = clobber;
}
/**
* Setter for jarFiles.
* @param jarFiles to set.
*/
public void setJarFiles(Set<File> jarFiles) {
this.jarFiles = jarFiles;
}
/**
* Filter for whether a ZipEntry begins with the sourceDirectory.
* @param file to test
* @return if ZipEntry path begins with sourceDirectory.
*/
private boolean startsWithSourceDirectory(ZipEntry file) {
return file.getName()
.toLowerCase(Locale.ENGLISH)
.startsWith(sourceDirectory.toLowerCase(Locale.ENGLISH));
}
/**
* Filter for whether a ZipEntry should be included.
* @param file to test
* @return if it should be included
*/
private boolean shouldInclude(ZipEntry file) {
return includes.stream()
.anyMatch(
include -> FilenameUtils.wildcardMatch(file.getName(), include)
);
}
/**
* Efficient and safe copy, only overwriting if destination differs.
* @param is input stream source
* @param dest output file
* @throws IOException on permission errors, etc..
*/
private void copyInputToDestIfDiffers(InputStream is, File dest) throws IOException {
File tempFile = File.createTempFile(TEMP_PREFIX, null);
FileUtils.copyInputStreamToFile(is, tempFile);
if (!FileUtils.contentEquals(tempFile, dest)) {
FileUtils.forceDelete(dest);
FileUtils.moveFile(tempFile, dest);
} else {
tempFile.delete();
}
}
/**
* Copy InputStream to file, respecting clobber settings.
* @param is input stream source
* @param dest output file
* @throws IOException on permission errors, etc..
*/
private void copyRespectingClobber(InputStream is, File dest) throws IOException {
if (dest.exists()) {
if (clobber) { // Overwrite existing file
getLog().info(String.format(
"File %s already exists and clobber is set; overwriting.",
dest.getName()
));
copyInputToDestIfDiffers(is, dest);
} else {
getLog().info(String.format(
"File %s already exists and clobber is not set; skipping.",
dest.getName()
));
}
} else {
FileUtils.copyInputStreamToFile(is, dest);
}
}
/**
* Copy file from jar to output directory.
* @param jar from which file will be copied
* @param fileInJar file to copy
* @throws MojoFailureException if file could not be copied, inadequate
* permissions, etc.
*/
private void copyFileInJarToOutput(
JarFile jar, ZipEntry fileInJar
) throws MojoFailureException {
String fullPath = fileInJar.getName();
// Drop sourceDirectory from file path
String relativePath = fullPath
.substring(fullPath.toLowerCase(Locale.ENGLISH)
.indexOf(sourceDirectory.toLowerCase(Locale.ENGLISH))
+ sourceDirectory.length());
// Determine output path
File target = new File(outputDirectory, relativePath);
try {
copyRespectingClobber(jar.getInputStream(fileInJar), target);
} catch (IOException e) {
throw new MojoFailureException(
"Failed to copy file " + fileInJar.getName()
);
}
}
/**
* Collect Jar files from dependencies and search through them for files
* matching the parameters of the plugin. Copy matching files into output
* directory specified by parameters.
*/
public void execute() throws MojoExecutionException, MojoFailureException {
if (jarFiles == null) {
this.jarFiles = project.getArtifacts().stream()
// Only process jar dependencies
.filter(artifact -> "jar".equals(artifact.getType()))
// Map to File
.map(Artifact::getFile)
.collect(Collectors.toSet());
}
for (File jar : jarFiles) {
try (JarFile jarFile = new JarFile(jar, false)) {
Set<ZipEntry> toCopy = jarFile.stream()
// Filter out directories
.filter(file -> !file.isDirectory())
// Filter out any files not in the source directory
.filter(this::startsWithSourceDirectory)
// Filter out files not matching any include wildcards
.filter(this::shouldInclude)
.collect(Collectors.toSet());
for (ZipEntry file : toCopy) {
getLog().info(String.format("Copying %s", file.getName()));
copyFileInJarToOutput(jarFile, file);
}
} catch (IOException e) {
throw new MojoFailureException(
String.format("Failed to open jar file %s!", jar.toString())
);
}
}
}
}
\ No newline at end of file
package org.org.eclipse.ice.dev.dependencyscraper;
import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.testing.MojoRule;
import org.apache.maven.plugin.MojoFailureException;
import org.junit.After;