mirror of
https://github.com/scm-manager/scm-manager.git
synced 2026-01-21 15:02:17 +01:00
merged
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
<name>scm-maven-plugins</name>
|
||||
|
||||
<modules>
|
||||
<module>scm-web-compressor</module>
|
||||
<module>scm-plugin-archetype</module>
|
||||
</modules>
|
||||
|
||||
@@ -30,4 +29,4 @@
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
<?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/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>sonia.scm.maven</groupId>
|
||||
<artifactId>scm-maven-plugins</artifactId>
|
||||
<version>1.0-M6-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>sonia.scm.maven</groupId>
|
||||
<artifactId>scm-web-compressor</artifactId>
|
||||
<packaging>maven-plugin</packaging>
|
||||
<version>1.0-M6-SNAPSHOT</version>
|
||||
<name>scm-web-compressor</name>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>sonia.scm</groupId>
|
||||
<artifactId>scm-core</artifactId>
|
||||
<version>1.0-M6-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.maven</groupId>
|
||||
<artifactId>maven-plugin-api</artifactId>
|
||||
<version>2.2.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.4.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.yahoo.platform.yui</groupId>
|
||||
<artifactId>yuicompressor</artifactId>
|
||||
<version>2.4.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.closure</groupId>
|
||||
<artifactId>compiler</artifactId>
|
||||
<version>20100917</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -1,267 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.maven;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import sonia.scm.util.ChecksumUtil;
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public abstract class AbstractWebCompressor implements WebCompressor
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* @param path
|
||||
*/
|
||||
protected abstract void appendElement(Document document, String path);
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
* @param target
|
||||
* @param encoding
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws MojoExecutionException
|
||||
* @throws MojoFailureException
|
||||
*/
|
||||
protected abstract void compress(File source, File target, String encoding)
|
||||
throws IOException, MojoExecutionException, MojoFailureException;
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract Elements selectElements(Document document);
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract String getExtension();
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param inputDirectory
|
||||
* @param element
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
protected abstract File getFile(File inputDirectory, Element element);
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* @param inputDirectory
|
||||
* @param outputDirectory
|
||||
* @param encoding
|
||||
* @param outputPrefix
|
||||
* @param concat
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws MojoExecutionException
|
||||
* @throws MojoFailureException
|
||||
*/
|
||||
@Override
|
||||
public void compress(Document document, File inputDirectory,
|
||||
File outputDirectory, String encoding,
|
||||
String outputPrefix, boolean concat)
|
||||
throws IOException, MojoExecutionException, MojoFailureException
|
||||
{
|
||||
Elements elements = selectElements(document);
|
||||
|
||||
if ((elements != null) &&!elements.isEmpty())
|
||||
{
|
||||
if (concat)
|
||||
{
|
||||
File uncompressedFile = concat(elements, inputDirectory);
|
||||
|
||||
compress(document, encoding, outputDirectory, outputPrefix,
|
||||
uncompressedFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (Element element : elements)
|
||||
{
|
||||
File uncompressedFile = getFile(inputDirectory, element);
|
||||
|
||||
compress(document, encoding, outputDirectory, outputPrefix,
|
||||
uncompressedFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
* @param target
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private void append(File source, File target) throws IOException
|
||||
{
|
||||
FileInputStream input = null;
|
||||
FileOutputStream output = null;
|
||||
|
||||
try
|
||||
{
|
||||
input = new FileInputStream(source);
|
||||
output = new FileOutputStream(target, true);
|
||||
IOUtil.copy(input, output);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(input);
|
||||
IOUtil.close(output);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* @param encoding
|
||||
* @param outputDirectory
|
||||
* @param outputPrefix
|
||||
* @param uncompressedFile
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws MojoExecutionException
|
||||
* @throws MojoFailureException
|
||||
*/
|
||||
private void compress(Document document, String encoding,
|
||||
File outputDirectory, String outputPrefix,
|
||||
File uncompressedFile)
|
||||
throws IOException, MojoExecutionException, MojoFailureException
|
||||
{
|
||||
File compressedFile = File.createTempFile("scm-", ".compressed");
|
||||
|
||||
compress(uncompressedFile, compressedFile, encoding);
|
||||
IOUtil.delete(uncompressedFile);
|
||||
|
||||
String checksum = ChecksumUtil.createChecksum(compressedFile);
|
||||
String name = checksum.concat(".").concat(getExtension());
|
||||
File scriptFile = new File(outputDirectory, name);
|
||||
|
||||
compressedFile.renameTo(scriptFile);
|
||||
|
||||
if (!scriptFile.exists())
|
||||
{
|
||||
|
||||
// TODO copy and remove
|
||||
throw new IOException("could not move ".concat(compressedFile.getPath()));
|
||||
}
|
||||
|
||||
StringBuilder path = new StringBuilder(outputPrefix);
|
||||
|
||||
if (!outputPrefix.endsWith("/"))
|
||||
{
|
||||
path.append("/");
|
||||
}
|
||||
|
||||
path.append(name);
|
||||
appendElement(document, path.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param elements
|
||||
* @param inputDirectory
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* @throws IOException
|
||||
*/
|
||||
private File concat(Elements elements, File inputDirectory) throws IOException
|
||||
{
|
||||
File tempFile = File.createTempFile("scm-", ".concat");
|
||||
|
||||
for (Element scriptEl : elements)
|
||||
{
|
||||
File file = getFile(inputDirectory, scriptEl);
|
||||
|
||||
if (file.exists())
|
||||
{
|
||||
append(file, tempFile);
|
||||
scriptEl.remove();
|
||||
}
|
||||
}
|
||||
|
||||
return tempFile;
|
||||
}
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.maven;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.google.javascript.jscomp.CompilerOptions;
|
||||
import com.google.javascript.jscomp.JSSourceFile;
|
||||
import com.google.javascript.jscomp.Result;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class ClosureWebCompressor extends AbstractWebCompressor
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String EXTENSION = "js";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* @param path
|
||||
*/
|
||||
@Override
|
||||
protected void appendElement(Document document, String path)
|
||||
{
|
||||
document.head().appendElement("script").attr("type",
|
||||
"text/javascript").attr("src", path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param sourceFile
|
||||
* @param targetFile
|
||||
* @param encoding
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws MojoExecutionException
|
||||
* @throws MojoFailureException
|
||||
*/
|
||||
@Override
|
||||
protected void compress(File sourceFile, File targetFile, String encoding)
|
||||
throws IOException, MojoExecutionException, MojoFailureException
|
||||
{
|
||||
com.google.javascript.jscomp.Compiler compiler =
|
||||
new com.google.javascript.jscomp.Compiler();
|
||||
CompilerOptions options = new CompilerOptions();
|
||||
final JSSourceFile extern = JSSourceFile.fromCode("externs.js",
|
||||
"function alert(x) {}");
|
||||
JSSourceFile source = JSSourceFile.fromFile(sourceFile);
|
||||
Result result = compiler.compile(extern, source, options);
|
||||
|
||||
if (!result.success)
|
||||
{
|
||||
throw new MojoFailureException("compression failed");
|
||||
}
|
||||
else
|
||||
{
|
||||
FileOutputStream output = null;
|
||||
|
||||
try
|
||||
{
|
||||
output = new FileOutputStream(targetFile);
|
||||
output.write(compiler.toSource().getBytes(encoding));
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected Elements selectElements(Document document)
|
||||
{
|
||||
return document.select("script[type=text/javascript][src]");
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getExtension()
|
||||
{
|
||||
return EXTENSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param inputDirectory
|
||||
* @param element
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected File getFile(File inputDirectory, Element element)
|
||||
{
|
||||
return new File(inputDirectory, element.attr("src"));
|
||||
}
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.maven;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public interface WebCompressor
|
||||
{
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* @param inputDirectory
|
||||
* @param outputDirectory
|
||||
* @param encoding
|
||||
* @param outputPrefix
|
||||
* @param concat
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws MojoExecutionException
|
||||
* @throws MojoFailureException
|
||||
*/
|
||||
public void compress(Document document, File inputDirectory,
|
||||
File outputDirectory, String encoding,
|
||||
String outputPrefix, boolean concat)
|
||||
throws IOException, MojoExecutionException, MojoFailureException;
|
||||
}
|
||||
@@ -1,311 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.maven;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import org.apache.maven.plugin.AbstractMojo;
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @goal compress
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class WebCompressorMojo extends AbstractMojo
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructs ...
|
||||
*
|
||||
*/
|
||||
public WebCompressorMojo()
|
||||
{
|
||||
compressorSet = new LinkedHashSet<WebCompressor>();
|
||||
compressorSet.add(new YuiWebCompressor());
|
||||
compressorSet.add(new ClosureWebCompressor());
|
||||
}
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @throws MojoExecutionException
|
||||
* @throws MojoFailureException
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws MojoExecutionException, MojoFailureException
|
||||
{
|
||||
IOUtil.mkdirs(outputDirectory);
|
||||
|
||||
OutputStream output = null;
|
||||
|
||||
try
|
||||
{
|
||||
Document document = Jsoup.parse(inputFile, encoding);
|
||||
File inputDirectory = inputFile.getParentFile();
|
||||
|
||||
for (WebCompressor compressor : compressorSet)
|
||||
{
|
||||
compressor.compress(document, inputDirectory, outputDirectory,
|
||||
encoding, outputPrefix, concat);
|
||||
}
|
||||
|
||||
IOUtil.mkdirs(outputFile.getParentFile());
|
||||
output = new FileOutputStream(outputFile);
|
||||
output.write(document.html().getBytes(encoding));
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new MojoExecutionException(ex.getMessage(), ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(output);
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<WebCompressor> getCompressorSet()
|
||||
{
|
||||
return compressorSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getEncoding()
|
||||
{
|
||||
return encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public File getInputFile()
|
||||
{
|
||||
return inputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public File getOutputDirectory()
|
||||
{
|
||||
return outputDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public File getOutputFile()
|
||||
{
|
||||
return outputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getOutputPrefix()
|
||||
{
|
||||
return outputPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public boolean isConcat()
|
||||
{
|
||||
return concat;
|
||||
}
|
||||
|
||||
//~--- set methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param compressorSet
|
||||
*/
|
||||
public void setCompressorSet(Set<WebCompressor> compressorSet)
|
||||
{
|
||||
this.compressorSet = compressorSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param concat
|
||||
*/
|
||||
public void setConcat(boolean concat)
|
||||
{
|
||||
this.concat = concat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param encoding
|
||||
*/
|
||||
public void setEncoding(String encoding)
|
||||
{
|
||||
this.encoding = encoding;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param inputFile
|
||||
*/
|
||||
public void setInputFile(File inputFile)
|
||||
{
|
||||
this.inputFile = inputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param outputDirectory
|
||||
*/
|
||||
public void setOutputDirectory(File outputDirectory)
|
||||
{
|
||||
this.outputDirectory = outputDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param outputFile
|
||||
*/
|
||||
public void setOutputFile(File outputFile)
|
||||
{
|
||||
this.outputFile = outputFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param outputPrefix
|
||||
*/
|
||||
public void setOutputPrefix(String outputPrefix)
|
||||
{
|
||||
this.outputPrefix = outputPrefix;
|
||||
}
|
||||
|
||||
//~--- fields ---------------------------------------------------------------
|
||||
|
||||
/** Field description */
|
||||
private Set<WebCompressor> compressorSet;
|
||||
|
||||
/**
|
||||
* @parameter
|
||||
*/
|
||||
private String encoding = "UTF-8";
|
||||
|
||||
/**
|
||||
* @parameter
|
||||
*/
|
||||
private boolean concat = true;
|
||||
|
||||
/**
|
||||
* @parameter
|
||||
* @required
|
||||
*/
|
||||
private File inputFile;
|
||||
|
||||
/**
|
||||
* @parameter default-value="${project.build.directory}/web-compressor"
|
||||
*/
|
||||
private File outputDirectory;
|
||||
|
||||
/**
|
||||
* @parameter
|
||||
* @required
|
||||
*/
|
||||
private File outputFile;
|
||||
|
||||
/**
|
||||
* @parameter
|
||||
* @required
|
||||
*/
|
||||
private String outputPrefix;
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
/**
|
||||
* Copyright (c) 2010, Sebastian Sdorra
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of SCM-Manager; nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* http://bitbucket.org/sdorra/scm-manager
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
package sonia.scm.maven;
|
||||
|
||||
//~--- non-JDK imports --------------------------------------------------------
|
||||
|
||||
import com.yahoo.platform.yui.compressor.CssCompressor;
|
||||
|
||||
import org.apache.maven.plugin.MojoExecutionException;
|
||||
import org.apache.maven.plugin.MojoFailureException;
|
||||
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import sonia.scm.util.IOUtil;
|
||||
|
||||
//~--- JDK imports ------------------------------------------------------------
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Sebastian Sdorra
|
||||
*/
|
||||
public class YuiWebCompressor extends AbstractWebCompressor
|
||||
{
|
||||
|
||||
/** Field description */
|
||||
public static final String EXTENSION = "css";
|
||||
|
||||
//~--- methods --------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
* @param path
|
||||
*/
|
||||
@Override
|
||||
protected void appendElement(Document document, String path)
|
||||
{
|
||||
document.head().appendElement("link").attr("type", "text/css").attr("rel",
|
||||
"stylesheet").attr("href", path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param source
|
||||
* @param target
|
||||
* @param encoding
|
||||
*
|
||||
* @throws IOException
|
||||
* @throws MojoExecutionException
|
||||
* @throws MojoFailureException
|
||||
*/
|
||||
@Override
|
||||
protected void compress(File source, File target, String encoding)
|
||||
throws IOException, MojoExecutionException, MojoFailureException
|
||||
{
|
||||
FileReader reader = null;
|
||||
FileWriter writer = null;
|
||||
|
||||
try
|
||||
{
|
||||
reader = new FileReader(source);
|
||||
|
||||
CssCompressor compressor = new CssCompressor(reader);
|
||||
|
||||
writer = new FileWriter(target);
|
||||
compressor.compress(writer, 5000);
|
||||
}
|
||||
finally
|
||||
{
|
||||
IOUtil.close(reader);
|
||||
IOUtil.close(writer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param document
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected Elements selectElements(Document document)
|
||||
{
|
||||
return document.select("link[type=text/css][href]");
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected String getExtension()
|
||||
{
|
||||
return EXTENSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method description
|
||||
*
|
||||
*
|
||||
* @param inputDirectory
|
||||
* @param element
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected File getFile(File inputDirectory, Element element)
|
||||
{
|
||||
return new File(inputDirectory, element.attr("href"));
|
||||
}
|
||||
}
|
||||
@@ -231,6 +231,49 @@
|
||||
|
||||
<profiles>
|
||||
|
||||
<profile>
|
||||
<id>release</id>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<configuration>
|
||||
<webResources>
|
||||
<resource>
|
||||
<directory>${project.build.directory}/web-compressor</directory>
|
||||
</resource>
|
||||
</webResources>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
<plugin>
|
||||
<groupId>sonia.maven</groupId>
|
||||
<artifactId>web-compressor</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>prepare-package</phase>
|
||||
<goals>
|
||||
<goal>compress-template</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<source>src/main/webapp/index.html</source>
|
||||
<target>${project.build.directory}/web-compressor/index.html</target>
|
||||
<compressCSS>false</compressCSS>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
<profile>
|
||||
<id>development</id>
|
||||
|
||||
|
||||
@@ -56,6 +56,7 @@ import java.util.Set;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -178,6 +179,13 @@ public class BasicSecurityContext implements WebSecurityContext
|
||||
{
|
||||
user = null;
|
||||
groups = new HashSet<String>();
|
||||
|
||||
HttpSession session = request.getSession(false);
|
||||
|
||||
if (session != null)
|
||||
{
|
||||
session.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
//~--- get methods ----------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user