Skip to content
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
64 changes: 0 additions & 64 deletions src/main/java/com/akathist/maven/plugins/launch4j/FileUtils.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
*/
package com.akathist.maven.plugins.launch4j;

import com.akathist.maven.plugins.launch4j.tools.ResourceIO;
import net.sf.launch4j.Builder;
import net.sf.launch4j.BuilderException;
import net.sf.launch4j.config.Config;
import net.sf.launch4j.config.ConfigPersister;
import net.sf.launch4j.config.ConfigPersisterException;

import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -81,7 +81,7 @@ public class Launch4jMojo extends AbstractMojo {
private String launch4jGroupId;

// intentionally non-static non-final so it can be hacked with reflection if someone really needs to
private String DEF_REQADMMAN_RES = "META-INF/resources/manifest-requireAdminRights-v1.xml";
private String DEF_REQADMMAN_RES = "META-INF/resources/manifest-require_admin_rights-v1.xml";

// intentionally non-static non-final so it can be hacked with reflection if someone really needs to
private String DEF_REQADMMAN_FILE = "target/classes/META-INF/manifest-requireAdminRights.xml";
Expand Down Expand Up @@ -371,7 +371,7 @@ private void doExecute() throws MojoExecutionException {

if (!disableVersionInfoDefaults) {
try {
if(versionInfo == null) {
if (versionInfo == null) {
versionInfo = new VersionInfo();
}
versionInfo.setLog(getLog());
Expand Down Expand Up @@ -412,7 +412,7 @@ private void doExecute() throws MojoExecutionException {
}

if (icon != null) {
c.setIcon(icon);
c.setIcon(icon);
}

if (versionInfo != null) {
Expand Down Expand Up @@ -536,11 +536,11 @@ private void processRequireAdminRights() throws MojoExecutionException {
metaInfDir.mkdir();

File manFile = new File(basedir, DEF_REQADMMAN_FILE);
byte[] manBytes = FileUtils.readResourceAsBytes(DEF_REQADMMAN_RES);
byte[] manBytes = ResourceIO.readResourceAsBytes(DEF_REQADMMAN_RES);

FileUtils.writeBytesIfDiff(manFile, manBytes);
ResourceIO.writeBytesIfDiff(manFile, manBytes);

byte[] savedBytes = FileUtils.readBytes(manFile);
byte[] savedBytes = ResourceIO.readBytes(manFile);
if (Arrays.equals(manBytes, savedBytes)) {
getLog().info("Manifest file written to " + manFile);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.akathist.maven.plugins.launch4j.tools;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

final public class ResourceIO {

private static final int DEFAULT_BUFFER_SIZE = 4 * 1024;

private ResourceIO() {
// avoids creating an instance of this class
}

private static byte[] readAllBytes(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();

byte[] buf = new byte[DEFAULT_BUFFER_SIZE];
int bytesRead;
while ((bytesRead = is.read(buf)) != -1) {
baos.write(buf, 0, bytesRead);
}

return baos.toByteArray();
}

public static byte[] readResourceAsBytes(String resName) throws IOException {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
try (InputStream is = cl.getResourceAsStream(resName)) {
if (is == null) {
throw new IOException("Resource not found: " + resName);
}
return readAllBytes(is);
}
}

public static void writeBytesIfDiff(File outFile, byte[] outBytes) throws IOException {
if (outFile.exists()) {
byte[] existingBytes = readBytes(outFile);
if (Arrays.equals(outBytes, existingBytes)) {
return;
}
}
writeBytes(outFile, outBytes);
}

public static byte[] readBytes(File inFile) throws IOException {
try (
FileInputStream fis = new FileInputStream(inFile);
BufferedInputStream bis = new BufferedInputStream(fis)
) {
return readAllBytes(bis);
}
}

public static void writeBytes(File outFile, byte[] outBytes) throws IOException {
try (
FileOutputStream fos = new FileOutputStream(outFile, false);
BufferedOutputStream bos = new BufferedOutputStream(fos)
) {
bos.write(outBytes);
bos.flush();
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
-->
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security>
<requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
</requestedPrivileges>
</security>
</trustInfo>
</assembly>