[java-identity-provider] 08/11: IDP-1499 New V4 Installer: Use Ant for delete
Rod Widdowson
rdw at steadingsoftware.com
Fri Oct 11 11:08:31 EDT 2019
This is an automated email from the git hooks/post-receive script.
rdw pushed a commit to branch master
in repository java-identity-provider.
View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=fc3c3ac4bc9540d1f2d33e1093283207eddba40e
commit fc3c3ac4bc9540d1f2d33e1093283207eddba40e
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Oct 11 14:36:07 2019 +0100
IDP-1499 New V4 Installer: Use Ant for delete
https://issues.shibboleth.net/jira/browse/IDP-1499
Usual reasons - it works better in edge cases (in mine that was readonly-ness)
---
.../shibboleth/idp/installer/impl/BuildWar.java | 24 +---
.../idp/installer/impl/CopyDistribution.java | 7 +-
.../idp/installer/impl/CopyingVisitor.java | 132 ---------------------
.../idp/installer/impl/DeletingVisitor.java | 76 ------------
.../idp/installer/impl/InstallerSupport.java | 50 ++++++--
.../net/shibboleth/idp/installer/impl/Test.java | 48 +++++---
6 files changed, 77 insertions(+), 260 deletions(-)
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java
index 9537fe2..31644a6 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/BuildWar.java
@@ -17,7 +17,6 @@
package net.shibboleth.idp.installer.impl;
-import java.io.IOException;
import java.nio.file.Path;
import org.apache.tools.ant.BuildException;
@@ -69,17 +68,9 @@ public class BuildWar extends AbstractInitializableComponent {
final Path warFile = target.resolve("war").resolve("idp.war");
log.info("Rebuilding {}, Version", warFile.toAbsolutePath(), currentState.getInstalledVersion());
- try {
- DeletingVisitor.deleteTree(target.resolve("webpapp"));
- } catch (final IOException e) {
- log.warn("Deleting {} failed", target.resolve("webpapp").toAbsolutePath(), e);
- }
+ InstallerSupport.deleteTree(target.resolve("webpapp"));
final Path webAppTmp =target.resolve("webpapp.tmp");
- try {
- DeletingVisitor.deleteTree(webAppTmp);
- } catch (final IOException e) {
- log.warn("Deleting {} failed", webAppTmp.toAbsolutePath(), e);
- }
+ InstallerSupport.deleteTree(webAppTmp);
final Path distWebApp = target.resolve("dist").resolve("webapp");
final Copy initial = InstallerSupport.getCopyTask(distWebApp, webAppTmp);
initial.setPreserveLastModified(true);
@@ -98,16 +89,9 @@ public class BuildWar extends AbstractInitializableComponent {
overlay.execute();
warFile.toFile().delete();
- final Jar jarTask = new Jar();
- jarTask.setDestFile(warFile.toFile());
- jarTask.setBasedir(webAppTmp.toFile());
- jarTask.setProject(InstallerSupport.ANT_PROJECT);
+ final Jar jarTask = InstallerSupport.createJarTask(webAppTmp, warFile);
log.info("Creating war file {}", warFile);
jarTask.execute();
- try {
- DeletingVisitor.deleteTree(webAppTmp);
- } catch (final IOException e) {
- log.warn("Deleting {} failed", webAppTmp, e);
- }
+ InstallerSupport.deleteTree(webAppTmp);
}
}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistribution.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistribution.java
index bff7c1d..9a0d36b 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistribution.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyDistribution.java
@@ -17,7 +17,6 @@
package net.shibboleth.idp.installer.impl;
-import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.text.SimpleDateFormat;
@@ -100,11 +99,7 @@ public final class CopyDistribution extends AbstractInitializableComponent {
throw new BuildException("Corrupt install - not a directory");
} else {
log.debug("Deleteing {} ", what);
- try {
- DeletingVisitor.deleteTree(what);
- } catch (final IOException e) {
- log.warn("Deleting {} failed", what, e);
- }
+ InstallerSupport.deleteTree(what);
}
}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyingVisitor.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyingVisitor.java
deleted file mode 100644
index d8ed275..0000000
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/CopyingVisitor.java
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements. See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID 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 net.shibboleth.idp.installer.impl;
-
-import java.io.IOException;
-import java.nio.file.FileAlreadyExistsException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.FileVisitor;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.StandardCopyOption;
-import java.nio.file.attribute.BasicFileAttributes;
-
-import javax.annotation.Nonnull;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import net.shibboleth.utilities.java.support.logic.Constraint;
-
-
-/** {@link FileVisitor} which copies a directory tree.
- * This class is based on that found in the javadoc for {@link FileVisitor}.
- *
- */
-public class CopyingVisitor extends SimpleFileVisitor<Path> {
-
- /** Class logger. */
- @Nonnull
- private static final Logger LOG = LoggerFactory.getLogger(CopyingVisitor.class);
-
- /** The 'to' directory.*/
- private final Path source;
-
- /** The 'from' directory.*/
- private final Path target;
-
- /** Do we overwriting or leave exiting in place. */
- private final boolean overWrite;
-
- /**
- * Constructor.
- *
- * @param from source to copy from.
- * @param to target to Copy to.
- * @param replace do we replace or leave in place.
- */
- public CopyingVisitor(final Path from, final Path to, final boolean replace) {
- Constraint.isTrue(!Files.exists(to) || Files.isDirectory(to), "Destination should be a directory or not exist");
- Constraint.isTrue(Files.exists(from) && Files.isDirectory(from), "Source should be a directory and exist");
-
- source = from;
- target = to;
- overWrite = replace;
- }
-
- /** {@inheritDoc} */
- @Override
- public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs) throws IOException {
- final Path targetDir = target.resolve(source.relativize(dir));
- try {
- if (!Files.exists(targetDir)) {
- LOG.debug("Creating Directory {}", targetDir);
- Files.copy(dir, targetDir);
- } else {
- LOG.debug("Directory {} exists already", targetDir);
- }
- } catch (final FileAlreadyExistsException e) {
- if (!Files.isDirectory(targetDir)) {
- throw e;
- }
- }
- return FileVisitResult.CONTINUE;
- }
-
- /** {@inheritDoc} */
- @Override
- public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
- final Path targetFile = target.resolve(source.relativize(file));
- if (overWrite) {
- LOG.debug("Overwriting file {}", targetFile);
- Files.copy(file, targetFile, StandardCopyOption.REPLACE_EXISTING);
- } else if (!Files.exists(targetFile)) {
- LOG.debug("Creating file {}", targetFile);
- Files.copy(file, targetFile);
- } else {
- LOG.debug("File {} exists, not copied", targetFile);
- }
- return FileVisitResult.CONTINUE;
- }
-
- /**
- * Method to copy a directory tree.
- *
- * @param from source to copy from.
- * @param to target to Copy to.
- * @throws IOException if the tree walks fails
- */
- public static void copyTree(final Path from, final Path to) throws IOException {
- copyTree(from, to, false);
- }
-
- /**
- * Method to copy a directory tree.
- *
- * @param from source to copy from.
- * @param to target to Copy to.
- * @param overWrite do we leave existing files in place or overwrite them?
- * @throws IOException if the tree walks fails
- */
- public static void copyTree(final Path from, final Path to, final boolean overWrite) throws IOException {
- LOG.debug("Copying From {} to {} overwrite = {}", from, to, overWrite);
- final CopyingVisitor visitor = new CopyingVisitor(from, to, overWrite);
- Files.walkFileTree(from, visitor);
- }
-}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/DeletingVisitor.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/DeletingVisitor.java
deleted file mode 100644
index d53d3bd..0000000
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/DeletingVisitor.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Licensed to the University Corporation for Advanced Internet Development,
- * Inc. (UCAID) under one or more contributor license agreements. See the
- * NOTICE file distributed with this work for additional information regarding
- * copyright ownership. The UCAID 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 net.shibboleth.idp.installer.impl;
-
-import java.io.IOException;
-import java.nio.file.FileVisitResult;
-import java.nio.file.FileVisitor;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.SimpleFileVisitor;
-import java.nio.file.attribute.BasicFileAttributes;
-
-import javax.annotation.Nonnull;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import net.shibboleth.utilities.java.support.logic.Constraint;
-
-
-/** {@link FileVisitor} which deletes a directory tree.
- * This class is based on that found in the javadoc for {@link FileVisitor}.
- *
- */
-public class DeletingVisitor extends SimpleFileVisitor<Path> {
-
- /** Class logger. */
- @Nonnull private final Logger log = LoggerFactory.getLogger(DeletingVisitor.class);
-
- /** {@inheritDoc} */
- @Override
- public FileVisitResult postVisitDirectory(final Path dir, final IOException e) throws IOException {
- if (e == null) {
- log.trace("Deleting Directory {}", dir);
- Files.delete(dir);
- return FileVisitResult.CONTINUE;
- }
- // directory iteration failed
- throw e;
- }
-
- /** {@inheritDoc} */
- @Override
- public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException {
- log.trace("Deleting file {}", file);
- Files.delete(file);
- return FileVisitResult.CONTINUE;
- }
-
- /**
- * Method to delete a tree.
- *
- * @param root where to delete
- * @throws IOException if the tree walks fails
- */
- public static void deleteTree(final Path root) throws IOException {
- Constraint.isTrue(!Files.exists(root) || Files.isDirectory(root),
- "Delete point should be a directory and must exist");
- Files.walkFileTree(root, new DeletingVisitor());
- }
-}
diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerSupport.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerSupport.java
index dd9fb2b..f6006a9 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerSupport.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/impl/InstallerSupport.java
@@ -24,6 +24,8 @@ import java.nio.file.Path;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Copy;
+import org.apache.tools.ant.taskdefs.Delete;
+import org.apache.tools.ant.taskdefs.Jar;
import org.apache.tools.ant.taskdefs.optional.windows.Attrib;
import org.apache.tools.ant.types.FileSet;
import org.apache.tools.ant.types.selectors.PresentSelector;
@@ -34,9 +36,6 @@ import org.slf4j.LoggerFactory;
/** General common names and helper functions for the installer. */
public final class InstallerSupport {
- /** Log. */
- public static final Logger LOG = LoggerFactory.getLogger(InstallerSupport.class);
-
/** The name of the file and the property with the current V4 installation value.*/
public static final String VERSION_NAME = "idp.installed.version";
@@ -44,7 +43,10 @@ public final class InstallerSupport {
public static final String PREVIOUS_VERSION_NAME = "idp.previous.installed.version";
/** A psuedo ant-project as parent. */
- public static final Project ANT_PROJECT = new Project();
+ private static final Project ANT_PROJECT = new Project();
+
+ /** Log. */
+ private static Logger log = LoggerFactory.getLogger(InstallerSupport.class);
/** Private Constructor. */
private InstallerSupport() {}
@@ -57,9 +59,9 @@ public final class InstallerSupport {
if (!Files.exists(dir)) {
try {
Files.createDirectories(dir);
- LOG.debug("Created directory {}", dir);
+ log.debug("Created directory {}", dir);
} catch (final IOException e) {
- LOG.error("Could no create {}", dir, e);
+ log.error("Could no create {}", dir, e);
throw new BuildException(e);
}
}
@@ -85,7 +87,7 @@ public final class InstallerSupport {
/** Populate a with all the missing files.
* @param from where to go from
* @param to where to go to
- * @throws BuildException
+ * @throws BuildException if basness occurrs
* Based on (for instance the following ant<code>
<!-- flows: copy from dist if not already present -->
<mkdir dir="${idp.target.dir}/flows" />
@@ -111,7 +113,7 @@ public final class InstallerSupport {
copy.addFileset(fromSet);
copy.setProject(ANT_PROJECT);
copy.execute();
- LOG.debug("Copied not-previously-existing files from {} to {}", from, to);
+ log.debug("Copied not-previously-existing files from {} to {}", from, to);
}
@@ -130,4 +132,36 @@ public final class InstallerSupport {
attrib.execute();
}
+ /** Delete the tree.
+ * @param where where
+ * @throws BuildException if badness occurrs
+ */
+ public static void deleteTree(final Path where) throws BuildException {
+ if (!Files.exists(where)) {
+ log.debug("Directory {} does not exist. Skipping delete.", where);
+ return;
+ }
+ if (!Files.isDirectory(where) ) {
+ log.error("Directory to be delete {} was a file");
+ throw new BuildException("Wanted a directory, found a file");
+ }
+ final Delete delete = new Delete();
+ delete.setDir(where.toFile());
+ delete.setFailOnError(false);
+ delete.execute();
+ }
+
+ /** Return a {@link Jar} task.
+ * @param baseDir where from
+ * @param destFile where to
+ * @return the jar task
+ */
+ public static Jar createJarTask(final Path baseDir, final Path destFile) {
+ final Jar jarTask = new Jar();
+ jarTask.setBasedir(baseDir.toFile());
+ jarTask.setDestFile(destFile.toFile());
+ jarTask.setProject(InstallerSupport.ANT_PROJECT);
+ return jarTask;
+ }
+
}
diff --git a/idp-installer/src/test/java/net/shibboleth/idp/installer/impl/Test.java b/idp-installer/src/test/java/net/shibboleth/idp/installer/impl/Test.java
index 0a9565e..07518d4 100644
--- a/idp-installer/src/test/java/net/shibboleth/idp/installer/impl/Test.java
+++ b/idp-installer/src/test/java/net/shibboleth/idp/installer/impl/Test.java
@@ -15,19 +15,20 @@
* limitations under the License.
*/
-package net.shibboleth.idp.installer;
+package net.shibboleth.idp.installer.impl;
import java.io.IOException;
-import java.nio.file.Path;
+import java.util.Properties;
import javax.annotation.Nonnull;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.Copy;
-import org.apache.tools.ant.types.FileSet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import net.shibboleth.idp.installer.impl.BuildWar;
+import net.shibboleth.idp.installer.impl.CopyDistribution;
+import net.shibboleth.idp.installer.impl.InstallerProperties;
+import net.shibboleth.idp.installer.impl.V4Install;
import net.shibboleth.utilities.java.support.component.ComponentInitializationException;
/**
@@ -37,25 +38,36 @@ public class Test {
/** Class logger. */
@Nonnull private final Logger log = LoggerFactory.getLogger(Test.class);
-
- private static Copy getCopyTask(final Path from, final Path to) {
- final Copy result = new Copy();
- result.setTodir(to.toFile());
- final FileSet fromSet = new FileSet();
- fromSet.setDir(from.toFile());
- result.addFileset(fromSet);
- return result;
- }
-
+
/**
* @param args
* @throws IOException
* @throws ComponentInitializationException
*/
public static void main(String[] args) throws IOException, ComponentInitializationException {
- Copy tsk = getCopyTask(Path.of("C:\\Users\\rdw\\Downloads"), Path.of("C:\\Users\\rdw\\Desktop\\fofofo"));
- tsk.setProject(new Project());
- tsk.execute();
+
+
+ System.setProperty(InstallerProperties.TARGET_DIR,"H:\\Downloads\\v4test");
+ System.setProperty(InstallerProperties.SOURCE_DIR,
+ "h:\\Perforce\\Juno\\New\\java-identity-provider\\idp-distribution\\target\\shibboleth-identity-provider-4.0.0-SNAPSHOT");
+ System.setProperty(InstallerProperties.ANT_BASE_DIR,
+ "h:\\Perforce\\Juno\\New\\java-identity-provider\\idp-distribution\\target\\shibboleth-identity-provider-4.0.0-SNAPSHOT\\bin");
+ System.setProperty(InstallerProperties.KEY_STORE_PASSWORD, "p1");
+ System.setProperty(InstallerProperties.SEALER_PASSWORD, "p1");
+ final InstallerProperties ip = new InstallerProperties(false);
+ ip.initialize();
+ final CurrentInstallState is = new CurrentInstallState(ip);
+ is.initialize();
+
+ final CopyDistribution dist = new CopyDistribution(ip, is);
+ dist.execute();
+
+ final V4Install inst = new V4Install(ip, is);
+ inst.execute();
+
+ final BuildWar bw = new BuildWar(ip, is);
+ bw.execute();
+
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list