Skip to content

Commit 0344146

Browse files
authored
Fixes issue with missing licence headers (#433)
1 parent 7f1151e commit 0344146

File tree

5 files changed

+126
-81
lines changed

5 files changed

+126
-81
lines changed

src/main/java/com/akathist/maven/plugins/launch4j/FileUtils.java

Lines changed: 0 additions & 64 deletions
This file was deleted.

src/main/java/com/akathist/maven/plugins/launch4j/Launch4jMojo.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
*/
2020
package com.akathist.maven.plugins.launch4j;
2121

22+
import com.akathist.maven.plugins.launch4j.tools.ResourceIO;
2223
import net.sf.launch4j.Builder;
2324
import net.sf.launch4j.BuilderException;
2425
import net.sf.launch4j.config.Config;
2526
import net.sf.launch4j.config.ConfigPersister;
2627
import net.sf.launch4j.config.ConfigPersisterException;
27-
2828
import org.apache.maven.execution.MavenSession;
2929
import org.apache.maven.plugin.AbstractMojo;
3030
import org.apache.maven.plugin.MojoExecutionException;
@@ -81,7 +81,7 @@ public class Launch4jMojo extends AbstractMojo {
8181
private String launch4jGroupId;
8282

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

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

372372
if (!disableVersionInfoDefaults) {
373373
try {
374-
if(versionInfo == null) {
374+
if (versionInfo == null) {
375375
versionInfo = new VersionInfo();
376376
}
377377
versionInfo.setLog(getLog());
@@ -412,7 +412,7 @@ private void doExecute() throws MojoExecutionException {
412412
}
413413

414414
if (icon != null) {
415-
c.setIcon(icon);
415+
c.setIcon(icon);
416416
}
417417

418418
if (versionInfo != null) {
@@ -536,11 +536,11 @@ private void processRequireAdminRights() throws MojoExecutionException {
536536
metaInfDir.mkdir();
537537

538538
File manFile = new File(basedir, DEF_REQADMMAN_FILE);
539-
byte[] manBytes = FileUtils.readResourceAsBytes(DEF_REQADMMAN_RES);
539+
byte[] manBytes = ResourceIO.readResourceAsBytes(DEF_REQADMMAN_RES);
540540

541-
FileUtils.writeBytesIfDiff(manFile, manBytes);
541+
ResourceIO.writeBytesIfDiff(manFile, manBytes);
542542

543-
byte[] savedBytes = FileUtils.readBytes(manFile);
543+
byte[] savedBytes = ResourceIO.readBytes(manFile);
544544
if (Arrays.equals(manBytes, savedBytes)) {
545545
getLog().info("Manifest file written to " + manFile);
546546
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package com.akathist.maven.plugins.launch4j.tools;
20+
21+
import java.io.BufferedInputStream;
22+
import java.io.BufferedOutputStream;
23+
import java.io.ByteArrayOutputStream;
24+
import java.io.File;
25+
import java.io.FileInputStream;
26+
import java.io.FileOutputStream;
27+
import java.io.IOException;
28+
import java.io.InputStream;
29+
import java.util.Arrays;
30+
31+
final public class ResourceIO {
32+
33+
private static final int DEFAULT_BUFFER_SIZE = 4 * 1024;
34+
35+
private ResourceIO() {
36+
// avoids creating an instance of this class
37+
}
38+
39+
private static byte[] readAllBytes(InputStream is) throws IOException {
40+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
41+
42+
byte[] buf = new byte[DEFAULT_BUFFER_SIZE];
43+
int bytesRead;
44+
while ((bytesRead = is.read(buf)) != -1) {
45+
baos.write(buf, 0, bytesRead);
46+
}
47+
48+
return baos.toByteArray();
49+
}
50+
51+
public static byte[] readResourceAsBytes(String resName) throws IOException {
52+
ClassLoader cl = Thread.currentThread().getContextClassLoader();
53+
try (InputStream is = cl.getResourceAsStream(resName)) {
54+
if (is == null) {
55+
throw new IOException("Resource not found: " + resName);
56+
}
57+
return readAllBytes(is);
58+
}
59+
}
60+
61+
public static void writeBytesIfDiff(File outFile, byte[] outBytes) throws IOException {
62+
if (outFile.exists()) {
63+
byte[] existingBytes = readBytes(outFile);
64+
if (Arrays.equals(outBytes, existingBytes)) {
65+
return;
66+
}
67+
}
68+
writeBytes(outFile, outBytes);
69+
}
70+
71+
public static byte[] readBytes(File inFile) throws IOException {
72+
try (
73+
FileInputStream fis = new FileInputStream(inFile);
74+
BufferedInputStream bis = new BufferedInputStream(fis)
75+
) {
76+
return readAllBytes(bis);
77+
}
78+
}
79+
80+
public static void writeBytes(File outFile, byte[] outBytes) throws IOException {
81+
try (
82+
FileOutputStream fos = new FileOutputStream(outFile, false);
83+
BufferedOutputStream bos = new BufferedOutputStream(fos)
84+
) {
85+
bos.write(outBytes);
86+
bos.flush();
87+
}
88+
}
89+
}

src/main/resources/META-INF/resources/manifest-requireAdminRights-v1.xml

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<!--
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
-->
22+
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
23+
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
24+
<security>
25+
<requestedPrivileges>
26+
<requestedExecutionLevel level="requireAdministrator" uiAccess="false"/>
27+
</requestedPrivileges>
28+
</security>
29+
</trustInfo>
30+
</assembly>

0 commit comments

Comments
 (0)