Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
semancik committed Nov 22, 2017
2 parents 14e9217 + bfb3c28 commit 415e22c
Show file tree
Hide file tree
Showing 7 changed files with 249 additions and 0 deletions.
10 changes: 10 additions & 0 deletions gui/admin-gui/pom.xml
Expand Up @@ -106,8 +106,18 @@
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<layoutFactory implementation="com.evolveum.midpoint.tools.layout.MidPointWarLayoutFactory"/>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.evolveum.midpoint</groupId>
<artifactId>midpoint-war-layout</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Expand Down
40 changes: 40 additions & 0 deletions tools/midpoint-war-layout/pom.xml
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2010-2017 Evolveum
~
~ Licensed 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.
-->

<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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>tools</artifactId>
<groupId>com.evolveum.midpoint</groupId>
<version>3.7-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>midpoint-war-layout</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-loader</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-loader-tools</artifactId>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed 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.evolveum.midpoint.tools.layout;

import org.springframework.boot.loader.WarLauncher;
import org.springframework.boot.loader.archive.Archive;
import org.springframework.boot.loader.archive.JarFileArchive;

import java.io.File;
import java.util.List;

/**
* Created by Viliam Repan (lazyman).
*/
public class MidPointWarLauncher extends WarLauncher {

public MidPointWarLauncher() {
}

public MidPointWarLauncher(Archive archive) {
super(archive);
}

public static void main(String[] args) throws Exception {
new MidPointWarLauncher().launch(args);
}

@Override
protected List<Archive> getClassPathArchives() throws Exception {
List<Archive> archives = super.getClassPathArchives();

File midPointHomeLib = getMidPointHomeLib();
if (midPointHomeLib == null || !midPointHomeLib.exists() || !midPointHomeLib.isDirectory()) {
return archives;
}

File[] files = midPointHomeLib.listFiles(file -> file.getName().toLowerCase().endsWith(".jar"));
if (files == null) {
return archives;
}

for (File file : files) {
archives.add(new JarFileArchive(file));
}

return archives;
}

private File getMidPointHomeLib() {
String midPointHome = System.getProperty("midpoint.home");
return new File(midPointHome, "lib");
}
}
@@ -0,0 +1,81 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed 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.evolveum.midpoint.tools.layout;

import org.springframework.boot.loader.tools.CustomLoaderLayout;
import org.springframework.boot.loader.tools.JarWriter;
import org.springframework.boot.loader.tools.Layouts;
import org.springframework.boot.loader.tools.LoaderClassesWriter;

import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.util.jar.JarFile;

/**
* Created by Viliam Repan (lazyman).
*/
public class MidPointWarLayout extends Layouts.War implements CustomLoaderLayout {

private String name;

public MidPointWarLayout(String name) {
this.name = name;
}

public String getName() {
return name;
}

@Override
public void writeLoadedClasses(LoaderClassesWriter writer) throws IOException {
JarWriter jarWriter = (JarWriter) writer;
writer.writeLoaderClasses();

JarFile self = createSelf();
jarWriter.writeEntries(self);
}

@Override
public String getLauncherClassName() {
return MidPointWarLauncher.class.getName();
}

private final JarFile createSelf() throws IOException {
try {
ProtectionDomain protectionDomain = getClass().getProtectionDomain();
CodeSource codeSource = protectionDomain.getCodeSource();
URI location = (codeSource == null ? null : codeSource.getLocation().toURI());
String path = (location == null ? null : location.getSchemeSpecificPart());

if (path == null) {
throw new IllegalStateException("Unable to determine code source archive");
}

File root = new File(path);
if (!root.exists()) {
throw new IllegalStateException("Unable to determine code source archive from " + root);
}

return new JarFile(root);
} catch (Exception e) {
throw new IOException("Could not find self jar", e);
}
}
}
@@ -0,0 +1,49 @@
/*
* Copyright (c) 2010-2017 Evolveum
*
* Licensed 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.evolveum.midpoint.tools.layout;

import org.springframework.boot.loader.tools.Layout;
import org.springframework.boot.loader.tools.LayoutFactory;

import java.io.File;

/**
* Created by Viliam Repan (lazyman).
*/
public class MidPointWarLayoutFactory implements LayoutFactory {

private static final String NAME = "midpoint-war";

private String name;

public MidPointWarLayoutFactory() {
this(NAME);
}

public MidPointWarLayoutFactory(String name) {
this.name = name;
}

public String getName() {
return name;
}

@Override
public Layout getLayout(File source) {
return new MidPointWarLayout(name);
}
}
@@ -0,0 +1 @@
org.springframework.boot.loader.tools.LayoutFactory=com.evolveum.midpoint.tools.layout.MidPointWarLayoutFactory
1 change: 1 addition & 0 deletions tools/pom.xml
Expand Up @@ -53,6 +53,7 @@
<module>gui-i18n</module>
<module>repo-ninja</module>
<module>schema-dist-maven-plugin</module>
<module>midpoint-war-layout</module>
</modules>
<dependencies> <!-- Not used, but required for surefire plugin not to complain -->
<dependency>
Expand Down

0 comments on commit 415e22c

Please sign in to comment.