Improved jar stuff copy.
This commit is contained in:
parent
0c74a970c7
commit
10b5eb4456
6 changed files with 187 additions and 137 deletions
|
@ -37,7 +37,6 @@ import javax.net.ssl.TrustManager;
|
|||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.apache.tika.Tika;
|
||||
|
@ -60,33 +59,6 @@ public class StatoolInfosUtils
|
|||
public static final DateTimeFormatter PATTERN_SHORTDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy", Locale.FRANCE);
|
||||
public static final DateTimeFormatter PATTERN_LONGDATE = DateTimeFormatter.ofPattern("dd/MM/yyyy HH':'mm", Locale.FRANCE);
|
||||
|
||||
/**
|
||||
* Copy ressource.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @param target
|
||||
* the target directory
|
||||
* @throws IOException
|
||||
*/
|
||||
public static void copyRessource(final String source, final File target) throws IOException
|
||||
{
|
||||
URL url = StatoolInfosUtils.class.getResource(source);
|
||||
|
||||
File finalTarget;
|
||||
if (target.isDirectory())
|
||||
{
|
||||
String fileName = FilenameUtils.getName(source);
|
||||
finalTarget = new File(target, fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
finalTarget = target;
|
||||
}
|
||||
|
||||
FileUtils.copyURLToFile(url, finalTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Epoch to local date time.
|
||||
*
|
||||
|
|
|
@ -35,6 +35,7 @@ import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
|
|||
import fr.devinsy.statoolinfos.properties.PathProperties;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyList;
|
||||
import fr.devinsy.statoolinfos.properties.PathPropertyUtils;
|
||||
import fr.devinsy.statoolinfos.util.URLUtils;
|
||||
|
||||
/**
|
||||
* The Class CrawlCache.
|
||||
|
@ -261,7 +262,7 @@ public class CrawlCache
|
|||
catch (IOException exception)
|
||||
{
|
||||
logger.warn("CatGeneratoring failed for {}: {}", seed, exception.getMessage());
|
||||
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/default-organization-logo.png", target);
|
||||
URLUtils.copyResource("/fr/devinsy/statoolinfos/htmlize/stuff/default-organization-logo.png", target);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -284,7 +285,7 @@ public class CrawlCache
|
|||
catch (IOException exception)
|
||||
{
|
||||
logger.warn("CatGeneratoring failed for {}: {}", seed, exception.getMessage());
|
||||
StatoolInfosUtils.copyRessource("/fr/devinsy/statoolinfos/htmlize/stuff/default-organization-logo.png", target);
|
||||
URLUtils.copyResource("/fr/devinsy/statoolinfos/htmlize/stuff/default-organization-logo.png", target);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -45,6 +45,7 @@ import fr.devinsy.statoolinfos.stats.organizations.OrganizationTurnoutStats;
|
|||
import fr.devinsy.statoolinfos.stats.services.HostProviderTypeStats;
|
||||
import fr.devinsy.statoolinfos.stats.services.HostServerTypeStats;
|
||||
import fr.devinsy.statoolinfos.stats.services.RegistrationStats;
|
||||
import fr.devinsy.statoolinfos.util.URLUtils;
|
||||
|
||||
/**
|
||||
* The Class Htmlizer.
|
||||
|
@ -142,110 +143,11 @@ public class Htmlizer
|
|||
// Copy commons files (index, images, favicon, css…).
|
||||
if (!new File(targetDirectory, "index.html").exists())
|
||||
{
|
||||
final String source = "/fr/devinsy/statoolinfos/htmlize/stuff/";
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "index.html", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "statoolinfos.css", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "Chart.bundle.min.js", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "sorttable.js", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "statoolinfos-logo.jpg", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "statoolinfos-logo.ico", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "statoolinfos-logo-name.jpg", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "statoolinfos-logo.jpg", new File(targetDirectory, "logo.jpg"));
|
||||
StatoolInfosUtils.copyRessource(source + "statoolinfos-logo.ico", new File(targetDirectory, "favicon.ico"));
|
||||
|
||||
//
|
||||
StatoolInfosUtils.copyRessource(source + "status-ok.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "status-warning.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "status-alert.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "status-error.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "status-over.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "status-void.png", targetDirectory);
|
||||
|
||||
//
|
||||
StatoolInfosUtils.copyRessource(source + "diaspora-logo.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "funkwhale-logo.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "funkwhale-logo2.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "mastodon-logo.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "mobilizon-logo.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "peertube-logo.png", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "pixelfed-logo.png", targetDirectory);
|
||||
|
||||
//
|
||||
File datatables = new File(targetDirectory, "DataTables");
|
||||
datatables.mkdirs();
|
||||
StatoolInfosUtils.copyRessource(source + "DataTables/datatables.min.css", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "DataTables/datatables.min.js", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "DataTables/datatables.french.js", targetDirectory);
|
||||
StatoolInfosUtils.copyRessource(source + "DataTables/sort_asc_disabled.png", datatables);
|
||||
StatoolInfosUtils.copyRessource(source + "DataTables/sort_asc.png", datatables);
|
||||
StatoolInfosUtils.copyRessource(source + "DataTables/sort_both.png", datatables);
|
||||
StatoolInfosUtils.copyRessource(source + "DataTables/sort_desc_disabled.png", datatables);
|
||||
StatoolInfosUtils.copyRessource(source + "DataTables/sort_desc.png", datatables);
|
||||
|
||||
//
|
||||
File circle = new File(targetDirectory, "circle-icons");
|
||||
circle.mkdirs();
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/barchart.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/barchart-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/booklet.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/booklet-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/bookshelf.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/bookshelf-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/clipboard.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/clipboard-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/contacts.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/contacts-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/creditcard.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/creditcard-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/cruise.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/cruise-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/dev.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/dev-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/document.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/document-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/email.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/email-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/global.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/global-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/mail.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/mail-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/money.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/money-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/profile.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/profile-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/rgb.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/rgb-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/ribbon.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/ribbon-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/toolbox.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/toolbox-mono.svg", circle);
|
||||
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/tools.svg", circle);
|
||||
StatoolInfosUtils.copyRessource(source + "circle-icons/tools-mono.svg", circle);
|
||||
|
||||
//
|
||||
File categories = new File(targetDirectory, "categories");
|
||||
categories.mkdirs();
|
||||
StatoolInfosUtils.copyRessource(source + "categories/default.svg", categories);
|
||||
String source = "/fr/devinsy/statoolinfos/htmlize/stuff/";
|
||||
URLUtils.copyDeeply(StatoolInfosUtils.class.getResource(source), targetDirectory);
|
||||
|
||||
URLUtils.copyResource(source + "statoolinfos-logo.jpg", new File(targetDirectory, "logo.jpg"));
|
||||
URLUtils.copyResource(source + "statoolinfos-logo.ico", new File(targetDirectory, "favicon.ico"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -9,9 +9,9 @@
|
|||
<link rel="stylesheet" type="text/css" href="statoolinfos.css" />
|
||||
<script src="sorttable.js"></script>
|
||||
<script src="Chart.bundle.min.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="datatables.min.css"/>
|
||||
<script type="text/javascript" src="datatables.min.js"></script>
|
||||
<script src="datatables.french.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="DataTables/datatables.min.css"/>
|
||||
<script type="text/javascript" src="DataTables/datatables.min.js"></script>
|
||||
<script src="DataTables/datatables.french.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div style="margin: 5px 10px 10px 10px;">
|
||||
|
|
175
src/fr/devinsy/statoolinfos/util/URLUtils.java
Normal file
175
src/fr/devinsy/statoolinfos/util/URLUtils.java
Normal file
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* Copyright (C) 2020 Christian Pierre MOMON <christian@momon.org>
|
||||
*
|
||||
* This file is part of StatoolInfos, simple service statistics tool.
|
||||
*
|
||||
* StatoolInfos is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* StatoolInfos is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with StatoolInfos. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package fr.devinsy.statoolinfos.util;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.JarURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.util.Enumeration;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import fr.devinsy.statoolinfos.core.StatoolInfosUtils;
|
||||
|
||||
/**
|
||||
* The Class URLUtils.
|
||||
*/
|
||||
public final class URLUtils
|
||||
{
|
||||
private static Logger logger = LoggerFactory.getLogger(URLUtils.class);
|
||||
|
||||
/**
|
||||
* Instantiates a new URL utils.
|
||||
*/
|
||||
private URLUtils()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy resources recursively.
|
||||
*
|
||||
* @param source
|
||||
* the origin url
|
||||
* @param target
|
||||
* the destination
|
||||
* @return true, if successful
|
||||
*/
|
||||
public static boolean copyDeeply(final URL source, final File target)
|
||||
{
|
||||
boolean result;
|
||||
|
||||
try
|
||||
{
|
||||
final URLConnection urlConnection = source.openConnection();
|
||||
if (urlConnection instanceof JarURLConnection)
|
||||
{
|
||||
result = copyURL(target, (JarURLConnection) urlConnection);
|
||||
result = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
FileUtils.copyDirectory(new File(source.getPath()), target);
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
catch (final IOException exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
result = false;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy resource.
|
||||
*
|
||||
* @param source
|
||||
* the source
|
||||
* @param target
|
||||
* the target
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
public static void copyResource(final String source, final File target) throws IOException
|
||||
{
|
||||
URL url = StatoolInfosUtils.class.getResource(source);
|
||||
|
||||
File finalTarget;
|
||||
if (target.isDirectory())
|
||||
{
|
||||
String fileName = FilenameUtils.getName(source);
|
||||
finalTarget = new File(target, fileName);
|
||||
}
|
||||
else
|
||||
{
|
||||
finalTarget = target;
|
||||
}
|
||||
|
||||
FileUtils.copyURLToFile(url, finalTarget);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy jar resources recursively.
|
||||
*
|
||||
* @param destDir
|
||||
* the dest dir
|
||||
* @param jarConnection
|
||||
* the jar connection
|
||||
* @return true, if successful
|
||||
* @throws IOException
|
||||
* Signals that an I/O exception has occurred.
|
||||
*/
|
||||
private static boolean copyURL(final File target, final JarURLConnection jarConnection) throws IOException
|
||||
{
|
||||
boolean result;
|
||||
|
||||
JarFile jarFile = jarConnection.getJarFile();
|
||||
|
||||
boolean ended = false;
|
||||
Enumeration<JarEntry> iterator = jarFile.entries();
|
||||
result = false;
|
||||
while (!ended)
|
||||
{
|
||||
if (iterator.hasMoreElements())
|
||||
{
|
||||
JarEntry entry = iterator.nextElement();
|
||||
|
||||
if (entry.getName().startsWith(jarConnection.getEntryName()))
|
||||
{
|
||||
String fileName = StringUtils.removeStart(entry.getName(), jarConnection.getEntryName());
|
||||
File file = new File(target, fileName);
|
||||
if (entry.isDirectory())
|
||||
{
|
||||
if (!file.exists())
|
||||
{
|
||||
logger.info("MKDIR [{}]", file);
|
||||
file.mkdirs();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
URL url = URLUtils.class.getResource("/" + entry.getName());
|
||||
File finalTarget = new File(target, fileName);
|
||||
|
||||
logger.info("COPY [{}][{}]", url, finalTarget);
|
||||
FileUtils.copyURLToFile(url, finalTarget);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ended = true;
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue