Skip to content

Commit

Permalink
Option for ignoring unchanged flump libs.
Browse files Browse the repository at this point in the history
Also, as I was driving by, made it a maven plugin. I think this is the right thing to do and that
no one else is using binary flump libs. But, if it does bother anyone, we could have a library with
the command line interface and the maven plugin could depend on that.

NOTE for IDE users: the artifact id changed, which sometimes means you need to reimport.
  • Loading branch information
jamie-threerings committed Jun 10, 2014
1 parent 48f753b commit e4f6164
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 89 deletions.
45 changes: 43 additions & 2 deletions tools/pom.xml
Expand Up @@ -7,8 +7,8 @@
<version>1.9-SNAPSHOT</version>
</parent>

<artifactId>tripleplay-tools</artifactId>
<packaging>jar</packaging>
<artifactId>tripleplay-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>

<name>Triple Play Tools</name>
<description>Build-time tools for use with Triple Play.</description>
Expand All @@ -20,5 +20,46 @@
<version>${project.version}</version>
<scope>compile</scope>
</dependency>

<!-- Maven wiring dependencies -->
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.1</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.1</version>
<configuration>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
<extractors>
<extractor>java-annotations</extractor>
</extractors>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
106 changes: 106 additions & 0 deletions tools/src/main/java/tripleplay/tools/ConvertFlumpLibsMojo.java
@@ -0,0 +1,106 @@
//
// Triple Play - utilities for use in PlayN-based games
// Copyright (c) 2011-2014, Three Rings Design, Inc. - All rights reserved.
// http://github.com/threerings/tripleplay/blob/master/LICENSE

package tripleplay.tools;

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;

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.project.MavenProject;

import playn.core.json.JsonImpl;

import tripleplay.flump.LibraryData;

@Mojo(name="flump", defaultPhase=LifecyclePhase.PROCESS_RESOURCES)
public class ConvertFlumpLibsMojo extends AbstractMojo
{
@Parameter(required=true, defaultValue="${project}")
public MavenProject project;

/** The root location for resources. */
@Parameter(required=true, defaultValue="src/main/resources")
public File resourceRoot;

/** The root location to save the converted binary files. By default, uses the build output. */
@Parameter
public File outputRoot;

/** The path within {@link #sourceRoot} to look for json files. */
@Parameter(defaultValue="assets/flump", property="flump.path")
public String path;

/** Specifies whether the conversion should skip source files with older modification times
* than their binary counterparts. */
@Parameter(defaultValue="true", property="flump.useModificationTimes")
public boolean useModificationTimes;

@Override public void execute ()
throws MojoExecutionException, MojoFailureException {
if (outputRoot == null) outputRoot = new File(project.getBuild().getOutputDirectory());
try {
int count = convert(path);
getLog().info("Converted " + count + " out of date libraries");
} catch (IOException ex) {
throw new MojoExecutionException("", ex);
}
}

protected int convert (String root)
throws IOException {
int count = 0;
File rootDir = new File(resourceRoot, root);
for (String item : rootDir.list()) {
String itemPath = root + File.separatorChar + item;
File child = new File(rootDir, item);
if (child.isDirectory()) {
count += convert(itemPath);
continue;
}
if (item.equals("library.json")) {
count += convert(child, itemPath);
}
}
return count;
}

protected LibraryData readLib (File jsonFile)
throws IOException {
Scanner scanner = new Scanner(jsonFile);
try {
return new LibraryData(new JsonImpl().parse(scanner.useDelimiter("\\Z").next()));
} finally {
scanner.close();
}
}

protected int convert (File jsonFile, String jsonPath)
throws IOException {
File bin = new File(outputRoot, jsonPath.replace(".json", ".bin"));
if (useModificationTimes && bin.exists() && bin.lastModified() > jsonFile.lastModified()) {
getLog().debug("Skipping up to date file " + bin);
return 0;
}

getLog().debug("Converting " + bin);
bin.getParentFile().mkdirs();
DataOutputStream ostream = new DataOutputStream(new FileOutputStream(bin));
try {
readLib(jsonFile).write(ostream);
} finally {
ostream.close();
}
return 1;
}
}
87 changes: 0 additions & 87 deletions tools/src/main/java/tripleplay/tools/ConvertFlumpLibsToBinary.java

This file was deleted.

0 comments on commit e4f6164

Please sign in to comment.