CHE-5431: Add versioning to installers (#5940)

* CHE-5431: Add versioning to installers
6.19.x
Anatoliy Bazko 2017-08-19 10:32:20 +00:00 committed by GitHub
parent cceed4b2bd
commit e67979d337
74 changed files with 569 additions and 743 deletions

View File

@ -20,16 +20,6 @@
</parent>
<artifactId>exec-agent</artifactId>
<name>Agent :: Exec</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Exec installer.
*
* @author Anatolii Bazko
* @see Installer
*/
@Singleton
public class ExecInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.exec.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.exec.script.sh";
@Inject
public ExecInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.exec",
"version": "1.0.0",
"name": "Exec",
"description": "Agent for command execution",
"dependencies": [],

View File

@ -20,14 +20,4 @@
</parent>
<artifactId>git-credentials-agent</artifactId>
<name>Git Credentials Agent</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,36 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Git credentials installer. Creates sh script that retrieves SSH keys from user preferences for
* console Git SSH operations. Injects Git username and email from user preferences to console Git
* preferences.
*
* @author Igor Vinokur
* @see Installer
*/
@Singleton
public class GitCredentialsInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.git.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.git.script.sh";
@Inject
public GitCredentialsInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.git-credentials",
"version": "1.0.0",
"name": "Git credentials",
"description": "Agent fetches SSH keys, Git username and email from CHE user preferences, and injects to console Git"
}

View File

@ -20,14 +20,4 @@
</parent>
<artifactId>ls-csharp-agent</artifactId>
<name>Language Server C# Agent</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Language server C# installer.
*
* @author Anatolii Bazko
* @see Installer
*/
@Singleton
public class LSCSharpInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ls.csharp.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.ls.csharp.script.sh";
@Inject
public LSCSharpInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.ls.csharp",
"version": "1.0.1",
"name": "C# language server",
"description": "C# intellisense",
"dependencies": [],

View File

@ -26,7 +26,7 @@ unset PACKAGES
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; }
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }
AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.csharp.binaries
AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.csharp.binaries/1.0.1
CHE_DIR=$HOME/che
LS_DIR=${CHE_DIR}/ls-csharp
LS_LAUNCHER=${LS_DIR}/launch.sh

View File

@ -20,14 +20,4 @@
</parent>
<artifactId>ls-json-agent</artifactId>
<name>Language Server Json Agent</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Language server Json installer.
*
* @author Anatolii Bazko
* @see Installer
*/
@Singleton
public class LSJsonInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ls.json.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.ls.json.script.sh";
@Inject
public LSJsonInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.ls.json",
"version": "1.0.1",
"name": "JSON language server",
"description": "JSON intellisense",
"dependencies": [],

View File

@ -26,7 +26,7 @@ unset PACKAGES
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; }
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }
AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.json.binaries
AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.json.binaries/1.0.1
CHE_DIR=$HOME/che
LS_DIR=${CHE_DIR}/ls-json
LS_LAUNCHER=${LS_DIR}/launch.sh

View File

@ -20,14 +20,4 @@
</parent>
<artifactId>ls-php-agent</artifactId>
<name>Language Server PHP Agent</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Language server Php installer.
*
* @author Anatolii Bazko
* @see Installer
*/
@Singleton
public class LSPhpInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ls.php.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.ls.php.script.sh";
@Inject
public LSPhpInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.ls.php",
"version": "2.0.1",
"name": "PHP language server",
"description": "PHP intellisense",
"dependencies": [],

View File

@ -26,7 +26,7 @@ unset PACKAGES
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; }
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }
AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.php.binaries
AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.php.binaries/2.0.1
CHE_DIR=$HOME/che
LS_DIR=${CHE_DIR}/ls-php
LS_LAUNCHER=${LS_DIR}/launch.sh

View File

@ -20,14 +20,4 @@
</parent>
<artifactId>ls-python-agent</artifactId>
<name>Language Server python Agent</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Language server python installer.
*
* @author Anatolii Bazko
* @see Installer
*/
@Singleton
public class LSPythonInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ls.python.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.ls.python.script.sh";
@Inject
public LSPythonInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.ls.python",
"version": "1.0.3",
"name": "Python language server",
"description": "Python intellisense",
"dependencies": [],

View File

@ -29,7 +29,7 @@ command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }
command -v python3.5 >/dev/null 2>&1 || { PYTHON_DEPS=${PYTHON_DEPS}" python3.5"; }
command -v pip3 >/dev/null 2>&1 || { PYTHON_DEPS=${PYTHON_DEPS}" pip3"; }
AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.python.binaries
AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.python.binaries/1.0.3
CHE_DIR=$HOME/che
LS_DIR=${CHE_DIR}/ls-python
LS_LAUNCHER=${LS_DIR}/launch.sh

View File

@ -20,14 +20,4 @@
</parent>
<artifactId>ls-typescript-agent</artifactId>
<name>Language Server typescript Agent</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Language server typescript installer.
*
* @author Anatolii Bazko
* @see Installer
*/
@Singleton
public class LSTypeScriptInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ls.typescript.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.ls.typescript.script.sh";
@Inject
public LSTypeScriptInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.ls.js-ts",
"version": "1.0.1",
"name": "TypeScript language server",
"description": "TypeScript intellisense",
"dependencies": [],

View File

@ -26,7 +26,7 @@ unset PACKAGES
command -v tar >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" tar"; }
command -v curl >/dev/null 2>&1 || { PACKAGES=${PACKAGES}" curl"; }
AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.typescript.binaries
AGENT_BINARIES_URI=https://codenvy.com/update/repository/public/download/org.eclipse.che.ls.typescript.binaries/1.0.1
CHE_DIR=$HOME/che
LS_DIR=${CHE_DIR}/ls-typescript
LS_LAUNCHER=${LS_DIR}/launch.sh

View File

@ -20,14 +20,4 @@
</parent>
<artifactId>ssh-agent</artifactId>
<name>SSH Agent</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Ssh installer.
*
* @author Anatolii Bazko
* @see Installer
*/
@Singleton
public class SshInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ssh.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.ssh.script.sh";
@Inject
public SshInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.ssh",
"version": "1.0.0",
"name": "SSH",
"description": "SSH server, key-pair generation",
"dependencies": [],

View File

@ -20,16 +20,6 @@
</parent>
<artifactId>terminal-agent</artifactId>
<name>Agent :: Terminal</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Terminal installer.
*
* @author Garagatyi Alexander
* @see Installer
*/
@Singleton
public class TerminalInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.terminal.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.terminal.script.sh";
@Inject
public TerminalInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.terminal",
"version": "1.0.0",
"name": "Terminal",
"description": "Embedded web terminal",
"dependencies": [],

View File

@ -20,14 +20,4 @@
</parent>
<artifactId>unison-agent</artifactId>
<name>Unison Agent</name>
<dependencies>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Unison installer.
*
* @author Anatolii Bazko
* @see Installer
*/
@Singleton
public class UnisonInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.unison.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.unison.script.sh";
@Inject
public UnisonInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.unison",
"version": "1.0.0",
"name": "File sync",
"description": "Unison File Synchronizer",
"dependencies": [],

View File

@ -14,9 +14,11 @@ import static com.google.inject.matcher.Matchers.subclassesOf;
import static org.eclipse.che.inject.Matchers.names;
import com.google.inject.AbstractModule;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.MapBinder;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;
import java.util.Set;
import javax.sql.DataSource;
import org.eclipse.che.api.core.rest.CheJsonProvider;
import org.eclipse.che.api.core.rest.MessageBodyAdapter;
@ -25,18 +27,8 @@ import org.eclipse.che.api.factory.server.FactoryAcceptValidator;
import org.eclipse.che.api.factory.server.FactoryCreateValidator;
import org.eclipse.che.api.factory.server.FactoryEditValidator;
import org.eclipse.che.api.factory.server.FactoryParametersResolver;
import org.eclipse.che.api.installer.ExecInstaller;
import org.eclipse.che.api.installer.GitCredentialsInstaller;
import org.eclipse.che.api.installer.LSCSharpInstaller;
import org.eclipse.che.api.installer.LSJsonInstaller;
import org.eclipse.che.api.installer.LSPhpInstaller;
import org.eclipse.che.api.installer.LSPythonInstaller;
import org.eclipse.che.api.installer.LSTypeScriptInstaller;
import org.eclipse.che.api.installer.SshInstaller;
import org.eclipse.che.api.installer.TerminalInstaller;
import org.eclipse.che.api.installer.UnisonInstaller;
import org.eclipse.che.api.installer.WsInstaller;
import org.eclipse.che.api.installer.server.InstallerModule;
import org.eclipse.che.api.installer.server.impl.InstallersProvider;
import org.eclipse.che.api.installer.shared.model.Installer;
import org.eclipse.che.api.recipe.JpaRecipeDao;
import org.eclipse.che.api.recipe.RecipeDao;
@ -162,18 +154,7 @@ public class WsMasterModule extends AbstractModule {
// installers
install(new InstallerModule());
Multibinder<Installer> installers = Multibinder.newSetBinder(binder(), Installer.class);
installers.addBinding().to(SshInstaller.class);
installers.addBinding().to(UnisonInstaller.class);
installers.addBinding().to(ExecInstaller.class);
installers.addBinding().to(TerminalInstaller.class);
installers.addBinding().to(WsInstaller.class);
installers.addBinding().to(LSPhpInstaller.class);
installers.addBinding().to(LSPythonInstaller.class);
installers.addBinding().to(LSJsonInstaller.class);
installers.addBinding().to(LSCSharpInstaller.class);
installers.addBinding().to(LSTypeScriptInstaller.class);
installers.addBinding().to(GitCredentialsInstaller.class);
binder().bind(new TypeLiteral<Set<Installer>>() {}).toProvider(InstallersProvider.class);
bind(org.eclipse.che.api.deploy.WsMasterAnalyticsAddresser.class);

View File

@ -21,24 +21,31 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.URLConnection;
import java.nio.channels.FileChannel;
import java.nio.file.FileSystem;
import java.nio.file.FileSystemAlreadyExistsException;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitOption;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.nio.file.ProviderNotFoundException;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.function.Consumer;
import javax.ws.rs.HttpMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -134,6 +141,34 @@ public class IoUtil {
return is;
}
/**
* Lists all children resources.
*
* @param parent the root path represented in {@link URI} format
* @param consumer consumer for children resources
* @throws java.io.IOException if any i/o error occur
* @throws ProviderNotFoundException if a provider supporting the URI scheme is not installed
*/
public static void listResources(URI parent, Consumer<Path> consumer) throws IOException {
FileSystem fileSystem = null;
try {
if (!"file".equals(parent.getScheme())) {
try {
fileSystem = FileSystems.newFileSystem(parent, Collections.emptyMap());
} catch (FileSystemAlreadyExistsException ignore) {
}
}
Path root = Paths.get(parent);
Files.list(root).forEach(consumer);
} finally {
// close FS only if only it has been initialized here
if (fileSystem != null) {
fileSystem.close();
}
}
}
/** Remove directory and all its sub-resources with specified path */
public static boolean removeDirectory(String pathToDir) {
return deleteRecursive(new File(pathToDir));

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.commons.lang;
import static org.testng.Assert.assertTrue;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.testng.annotations.Test;
/** @author Anatolii Bazko */
public class IoUtilTest {
@Test
public void shouldListFileResources() throws Exception {
List<String> resources = new ArrayList<>();
IoUtil.listResources(
getClass().getResource("/").toURI(), path -> resources.add(path.getFileName().toString()));
assertTrue(resources.contains("logback-test.xml"));
assertTrue(resources.contains("findbugs-exclude.xml"));
}
@Test
public void shouldListChildrenResourcesInJar() throws Exception {
URL testJar = Thread.currentThread().getContextClassLoader().getResource("che/che.jar");
URI codenvyDir = URI.create("jar:" + testJar + "!/codenvy");
List<String> resources = new ArrayList<>();
IoUtil.listResources(codenvyDir, path -> resources.add(path.getFileName().toString()));
assertTrue(resources.contains("a.json"));
assertTrue(resources.contains("b.json"));
}
@Test
public void shouldListParentResourcesInJar() throws Exception {
URL testJar = Thread.currentThread().getContextClassLoader().getResource("che/che.jar");
URI codenvyDir = URI.create("jar:" + testJar + "!/");
List<String> resources = new ArrayList<>();
IoUtil.listResources(codenvyDir, path -> resources.add(path.getFileName().toString()));
assertTrue(resources.contains("codenvy/"));
}
}

View File

@ -25,10 +25,10 @@ import org.eclipse.che.api.core.ValidationException;
import org.eclipse.che.api.core.model.workspace.config.Environment;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.installer.server.InstallerRegistry;
import org.eclipse.che.api.workspace.server.Utils;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException;
import org.eclipse.che.api.workspace.server.spi.RuntimeContext;
import org.eclipse.che.api.workspace.shared.Utils;
import org.eclipse.che.plugin.docker.client.json.ContainerListEntry;
import org.eclipse.che.workspace.infrastructure.docker.container.DockerContainers;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerEnvironment;

View File

@ -25,6 +25,7 @@ import org.eclipse.che.api.core.ValidationException;
import org.eclipse.che.api.core.model.workspace.config.Environment;
import org.eclipse.che.api.core.model.workspace.config.MachineConfig;
import org.eclipse.che.api.core.model.workspace.config.ServerConfig;
import org.eclipse.che.api.installer.server.impl.InstallerFqn;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerContainerConfig;
@ -94,8 +95,8 @@ public class EnvironmentValidator {
.stream()
.filter(
entry ->
entry.getValue().getInstallers() != null
&& entry.getValue().getInstallers().contains("org.eclipse.che.ws-agent"))
InstallerFqn.idInKeyList(
"org.eclipse.che.ws-agent", entry.getValue().getInstallers()))
.map(Map.Entry::getKey)
.collect(toList());

View File

@ -13,10 +13,10 @@ package org.eclipse.che.workspace.infrastructure.docker.local.installer;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.Utils;
import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException;
import org.eclipse.che.api.workspace.shared.Utils;
import org.eclipse.che.inject.CheBootstrap;
import org.eclipse.che.workspace.infrastructure.docker.local.server.DockerExtConfBindingProvider;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerContainerConfig;

View File

@ -11,7 +11,7 @@
package org.eclipse.che.workspace.infrastructure.docker.local.projects;
import static java.lang.String.format;
import static org.eclipse.che.api.workspace.shared.Utils.getDevMachineName;
import static org.eclipse.che.api.workspace.server.Utils.getDevMachineName;
import static org.slf4j.LoggerFactory.getLogger;
import com.google.common.base.Strings;

View File

@ -300,7 +300,7 @@ public class DockerInternalRuntimeTest {
return new InstallerImpl(
"installer_" + i,
"installer_name" + i,
String.valueOf(i),
String.valueOf(i) + ".0.0",
"test installer",
Collections.emptyList(),
emptyMap(),

View File

@ -16,10 +16,10 @@ import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.Utils;
import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl;
import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl;
import org.eclipse.che.api.workspace.server.spi.RuntimeIdentityImpl;
import org.eclipse.che.api.workspace.shared.Utils;
import org.eclipse.che.inject.CheBootstrap;
import org.eclipse.che.workspace.infrastructure.docker.local.server.DockerExtConfBindingProvider;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerContainerConfig;

View File

@ -17,11 +17,11 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException;
import java.util.Collections;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.Utils;
import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl;
import org.eclipse.che.api.workspace.server.model.impl.MachineConfigImpl;
import org.eclipse.che.api.workspace.server.spi.InternalInfrastructureException;
import org.eclipse.che.api.workspace.server.spi.RuntimeIdentityImpl;
import org.eclipse.che.api.workspace.shared.Utils;
import org.eclipse.che.commons.lang.os.WindowsPathEscaper;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerContainerConfig;
import org.eclipse.che.workspace.infrastructure.docker.model.DockerEnvironment;

View File

@ -28,9 +28,9 @@ import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.installer.server.InstallerRegistry;
import org.eclipse.che.api.installer.server.exception.InstallerException;
import org.eclipse.che.api.installer.shared.model.Installer;
import org.eclipse.che.api.workspace.server.Utils;
import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.shared.Utils;
import org.eclipse.che.workspace.infrastructure.openshift.ServerExposer;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.provision.ConfigurationProvisioner;

View File

@ -25,9 +25,9 @@ import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import org.eclipse.che.api.core.model.workspace.runtime.RuntimeIdentity;
import org.eclipse.che.api.workspace.server.Utils;
import org.eclipse.che.api.workspace.server.model.impl.EnvironmentImpl;
import org.eclipse.che.api.workspace.server.spi.InfrastructureException;
import org.eclipse.che.api.workspace.shared.Utils;
import org.eclipse.che.workspace.infrastructure.openshift.environment.OpenShiftEnvironment;
import org.eclipse.che.workspace.infrastructure.openshift.provision.ConfigurationProvisioner;

View File

@ -12,7 +12,7 @@ package org.eclipse.che.workspace.infrastructure.openshift.provision.installer;
import static java.util.Collections.emptyMap;
import static java.util.Collections.singletonList;
import static org.eclipse.che.api.workspace.shared.Utils.WSAGENT_INSTALLER;
import static org.eclipse.che.api.workspace.server.Utils.WSAGENT_INSTALLER;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.mock;

View File

@ -11,7 +11,7 @@
package org.eclipse.che.workspace.infrastructure.openshift.provision.volume;
import static java.util.Collections.singletonList;
import static org.eclipse.che.api.workspace.shared.Utils.WSAGENT_INSTALLER;
import static org.eclipse.che.api.workspace.server.Utils.WSAGENT_INSTALLER;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;

View File

@ -25,10 +25,6 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency -->
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
</dependency>
<!-- dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
@ -37,10 +33,6 @@
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency -->
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-installer</artifactId>
</dependency>
<!-- dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>

View File

@ -1,34 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.io.IOException;
import org.eclipse.che.api.installer.server.model.impl.BasicInstaller;
import org.eclipse.che.api.installer.shared.model.Installer;
/**
* Workspace installer.
*
* @author Anatolii Bazko
* @see Installer
*/
@Singleton
public class WsInstaller extends BasicInstaller {
private static final String AGENT_DESCRIPTOR = "org.eclipse.che.ws-agent.json";
private static final String AGENT_SCRIPT = "org.eclipse.che.ws-agent.script.sh";
@Inject
public WsInstaller() throws IOException {
super(AGENT_DESCRIPTOR, AGENT_SCRIPT);
}
}

View File

@ -1,5 +1,6 @@
{
"id": "org.eclipse.che.ws-agent",
"version": "1.0.0",
"name": "Workspace API",
"description": "Workspace API support",
"dependencies": [

View File

@ -50,6 +50,10 @@
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.che.core</groupId>
<artifactId>che-core-api-core</artifactId>

View File

@ -90,13 +90,14 @@ public interface InstallerRegistry {
/**
* Traverses dependencies of all listed installers and returns properly ordered list of
* non-duplicated installer descriptions
* non-duplicated installer descriptions. If any of {@code installerKeys} contains only id then
* the latest version of this installer will be used to fetch dependencies.
*
* @param installers installers to fetch dependencies and order
* @param installerKeys installers keys to fetch dependencies and order
* @return list of installers
* @throws IllegalInstallerKeyException if specified installer key has wrong format
* @throws InstallerNotFoundException if some of specified installer is not found in the registry
* @throws InstallerException if unexpected error occurred
*/
List<Installer> getOrderedInstallers(List<String> installers) throws InstallerException;
List<Installer> getOrderedInstallers(List<String> installerKeys) throws InstallerException;
}

View File

@ -11,6 +11,7 @@
package org.eclipse.che.api.installer.server.impl;
import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;
import org.eclipse.che.api.installer.server.exception.IllegalInstallerKeyException;
import org.eclipse.che.api.installer.shared.model.Installer;
@ -18,16 +19,20 @@ import org.eclipse.che.commons.annotation.Nullable;
/** @author Anatolii Bazko */
public class InstallerFqn implements Serializable {
public static final String DEFAULT_VERSION = "latest";
public static final String LATEST_VERSION_TAG = "latest";
private String id;
private String version;
public InstallerFqn() {}
public InstallerFqn(String id) {
this(id, null);
}
public InstallerFqn(String id, @Nullable String version) {
this.id = id;
this.version = version == null ? DEFAULT_VERSION : version;
this.version = version == null ? LATEST_VERSION_TAG : version;
}
public String getId() {
@ -65,6 +70,44 @@ public class InstallerFqn implements Serializable {
return id + ":" + version;
}
public boolean hasLatestTag() {
return LATEST_VERSION_TAG.equals(version);
}
/** Indicates if installer id is contained in the giving list of keys. */
public static boolean idInKeyList(
String installerId, @Nullable Collection<String> installerKeys) {
Objects.requireNonNull(installerId, "Installer ID is null");
if (installerKeys == null) {
return false;
}
for (String installerKey : installerKeys) {
if (installerKey.equals(installerId) || installerKey.startsWith(installerId + ":")) {
return true;
}
}
return false;
}
/** Indicates if installer id is contained in the giving list of FQNs. */
public static boolean idInFqnList(
String installerId, @Nullable Collection<InstallerFqn> installerFqns) {
Objects.requireNonNull(installerId, "Installer ID is null");
if (installerFqns == null) {
return false;
}
for (InstallerFqn fqn : installerFqns) {
if (fqn.getId().equals(installerId)) {
return true;
}
}
return false;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer.server.impl;
import static java.lang.String.format;
import com.google.inject.Singleton;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.eclipse.che.api.installer.server.exception.InstallerException;
import org.eclipse.che.api.installer.shared.model.Installer;
/** @author Anatolii Bazko */
@Singleton
public class InstallerValidator {
/**
* Checks {@link Installer} for valid parameters.
*
* @param installer the installer to check
* @throws InstallerException
*/
public void validate(Installer installer) throws InstallerException {
validateVersion(installer);
}
private void validateVersion(Installer installer) throws InstallerException {
try {
new ComparableVersion(installer.getVersion());
} catch (Exception e) {
throw new InstallerException(
format(
"Installer '%s' has illegal version format '%s'.",
InstallerFqn.of(installer).toKey(), installer.getVersion()),
e);
}
}
}

View File

@ -0,0 +1,114 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer.server.impl;
import static java.nio.file.Files.isDirectory;
import com.google.inject.Provider;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.che.api.installer.shared.dto.InstallerDto;
import org.eclipse.che.api.installer.shared.model.Installer;
import org.eclipse.che.commons.lang.IoUtil;
import org.eclipse.che.dto.server.DtoFactory;
/**
* Scans resources to create {@link Installer} based upon them. To be able to find appropriate
* resources the structure has to be the follow:
*
* <p>installers | -- version_1 | |------- installer_1_version_1.script.sh | |-------
* installer_1_version_1.json -- version_2 |------- installer_1_version_2.script.sh |-------
* installer_1_version_2.json
*
* @author Anatolii Bazko
*/
public class InstallersProvider implements Provider<Set<Installer>> {
@Override
public Set<Installer> get() {
Set<Installer> installers = new HashSet<>();
try {
Enumeration<URL> installerResources =
Thread.currentThread().getContextClassLoader().getResources("/installers");
while (installerResources.hasMoreElements()) {
URL installerResource = installerResources.nextElement();
IoUtil.listResources(
installerResource.toURI(),
versionDir -> {
if (!isDirectory(versionDir)) {
return;
}
List<Path> descriptors = findInstallersDescriptors(versionDir);
for (Path descriptor : descriptors) {
Optional<Path> script = findInstallerScript(descriptor);
script.ifPresent(
path -> {
Installer installer = init(descriptor, script.get());
installers.add(installer);
});
}
});
}
} catch (IOException | URISyntaxException e) {
throw new IllegalStateException(e);
}
return installers;
}
private List<Path> findInstallersDescriptors(Path dir) {
try {
return Files.find(dir, 1, (path, basicFileAttributes) -> path.toString().endsWith(".json"))
.collect(Collectors.toList());
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
private Optional<Path> findInstallerScript(Path descriptor) {
String scriptFileName =
descriptor.getFileName().toString().replaceAll("[.]json$", ".script.sh");
try {
return Files.find(
descriptor.getParent(),
1,
(path, basicFileAttributes) -> path.getFileName().toString().equals(scriptFileName))
.findFirst();
} catch (IOException e) {
throw new IllegalStateException(e);
}
}
private Installer init(Path descriptorPath, Path scriptPath) {
try {
String descriptor = IoUtil.readAndCloseQuietly(Files.newInputStream(descriptorPath));
String script = IoUtil.readAndCloseQuietly(Files.newInputStream(scriptPath));
InstallerDto installer =
DtoFactory.getInstance().createDtoFromJson(descriptor, InstallerDto.class);
return installer.withScript(script);
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
}

View File

@ -10,21 +10,28 @@
*/
package org.eclipse.che.api.installer.server.impl;
import static java.lang.String.format;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.eclipse.che.api.core.Page;
import org.eclipse.che.api.installer.server.InstallerRegistry;
import org.eclipse.che.api.installer.server.exception.InstallerAlreadyExistsException;
import org.eclipse.che.api.installer.server.exception.InstallerException;
import org.eclipse.che.api.installer.server.exception.InstallerNotFoundException;
import org.eclipse.che.api.installer.server.model.impl.InstallerImpl;
import org.eclipse.che.api.installer.server.spi.InstallerDao;
import org.eclipse.che.api.installer.shared.model.Installer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Local implementation of the {@link InstallerRegistry}. Persistent layer is represented by {@link
@ -35,38 +42,51 @@ import org.eclipse.che.api.installer.shared.model.Installer;
*/
@Singleton
public class LocalInstallerRegistry implements InstallerRegistry {
private static final Logger LOG = LoggerFactory.getLogger(LocalInstallerRegistry.class);
private final InstallerDao installerDao;
private final InstallerValidator installerValidator;
/** Primary registry initialization with shipped installers. */
@Inject
public LocalInstallerRegistry(Set<Installer> installers, InstallerDao installerDao)
public LocalInstallerRegistry(
Set<Installer> installers, InstallerDao installerDao, InstallerValidator installerValidator)
throws InstallerException {
this.installerDao = installerDao;
this.installerValidator = installerValidator;
for (Installer i : installers) {
InstallerImpl installer = new InstallerImpl(i);
doInit(installerDao, i);
}
}
try {
installerDao.create(installer);
} catch (InstallerAlreadyExistsException e) {
// ignore
}
private void doInit(InstallerDao installerDao, Installer i) throws InstallerException {
String installerKey = InstallerFqn.of(i).toKey();
installerValidator.validate(i);
try {
installerDao.create(new InstallerImpl(i));
LOG.info(format("Installer '%s' added to the registry.", installerKey));
} catch (InstallerAlreadyExistsException e) {
LOG.info(format("Installer '%s' already exists in the registry.", installerKey));
}
}
@Override
public void add(Installer installer) throws InstallerException {
installerValidator.validate(installer);
installerDao.create(new InstallerImpl(installer));
}
@Override
public void update(Installer installer) throws InstallerException {
installerValidator.validate(installer);
installerDao.update(new InstallerImpl(installer));
}
@Override
public void remove(String installerKey) throws InstallerException {
installerDao.remove(InstallerFqn.parse(installerKey));
InstallerFqn installerFqn = InstallerFqn.parse(installerKey);
installerDao.remove(stripOffLatestTag(installerFqn));
}
@Override
@ -86,44 +106,92 @@ public class LocalInstallerRegistry implements InstallerRegistry {
}
@Override
public List<Installer> getOrderedInstallers(List<String> installers) throws InstallerException {
Map<InstallerFqn, Installer> sorted = new LinkedHashMap<>();
public List<Installer> getOrderedInstallers(List<String> installerKeys)
throws InstallerException {
LinkedHashMap<InstallerFqn, Installer> sorted = new LinkedHashMap<>();
Set<InstallerFqn> pending = new HashSet<>();
for (String installer : installers) {
doSort(InstallerFqn.parse(installer), sorted, pending);
for (String installer : installerKeys) {
InstallerFqn installerFqn = InstallerFqn.parse(installer);
doSort(stripOffLatestTag(installerFqn), sorted, pending);
}
return new ArrayList<>(sorted.values());
}
private void doSort(
InstallerFqn installerFqn, Map<InstallerFqn, Installer> sorted, Set<InstallerFqn> pending)
InstallerFqn installerFqn,
LinkedHashMap<InstallerFqn, Installer> sorted,
Set<InstallerFqn> pending)
throws InstallerException {
if (sorted.containsKey(installerFqn)) {
if (sorted.keySet().contains(installerFqn)) {
return;
}
Installer installer = doGet(installerFqn);
pending.add(installerFqn);
for (String dependency : installer.getDependencies()) {
InstallerFqn dependencyFqn = InstallerFqn.parse(dependency);
Installer installer = doGet(installerFqn);
for (String dependencyKey : installer.getDependencies()) {
InstallerFqn dependencyFqn = stripOffLatestTag(InstallerFqn.parse(dependencyKey));
if (pending.contains(dependencyFqn)) {
throw new InstallerException(
String.format(
format(
"Installers circular dependency found between '%s' and '%s'",
dependencyFqn.toString(), installerFqn));
dependencyFqn, installerFqn));
}
doSort(dependencyFqn, sorted, pending);
}
if (InstallerFqn.idInFqnList(installerFqn.getId(), sorted.keySet())) {
throw new InstallerException(
format(
"Installers dependencies conflict. Several version '%s' and '%s' of the some id '%s",
installerFqn.getVersion(),
sorted
.keySet()
.stream()
.filter(i -> i.getId().equals(installerFqn.getId()))
.findFirst()
.get()
.getVersion(),
installerFqn.getId()));
}
sorted.put(installerFqn, installer);
pending.remove(InstallerFqn.of(installer));
}
private Installer doGet(InstallerFqn installerFqn) throws InstallerException {
return installerDao.getByFqn(installerFqn);
return installerDao.getByFqn(stripOffLatestTag(installerFqn));
}
private InstallerFqn stripOffLatestTag(InstallerFqn installerFqn) throws InstallerException {
if (!installerFqn.hasLatestTag()) {
return installerFqn;
}
Optional<ComparableVersion> latestVersion =
getVersions(installerFqn.getId())
.stream()
.map(
v -> {
try {
return new ComparableVersion(v);
} catch (Exception e) {
LOG.error(
format(
"Invalid version '%s' for installer '%s'. Skipped.",
installerFqn.getId(), v));
return null;
}
})
.filter(Objects::nonNull)
.max(ComparableVersion::compareTo);
if (!latestVersion.isPresent()) {
throw new InstallerNotFoundException(
format("No installer '%s' found of the latest version", installerFqn.getId()));
}
return new InstallerFqn(installerFqn.getId(), latestVersion.get().toString());
}
}

View File

@ -218,7 +218,8 @@ public class RemoteInstallerRegistry implements InstallerRegistry {
}
@Override
public List<Installer> getOrderedInstallers(List<String> installers) throws InstallerException {
public List<Installer> getOrderedInstallers(List<String> installerKeys)
throws InstallerException {
checkConfiguration();
try {
@ -230,7 +231,7 @@ public class RemoteInstallerRegistry implements InstallerRegistry {
.build()
.toString())
.usePostMethod()
.setBody(installers)
.setBody(installerKeys)
.request()
.asList(InstallerDto.class));
} catch (NotFoundException e) {

View File

@ -1,104 +0,0 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.installer.server.model.impl;
import static java.lang.String.format;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import org.eclipse.che.api.core.model.workspace.config.ServerConfig;
import org.eclipse.che.api.installer.shared.dto.InstallerDto;
import org.eclipse.che.api.installer.shared.model.Installer;
import org.eclipse.che.commons.lang.IoUtil;
import org.eclipse.che.dto.server.DtoFactory;
/**
* Basic implementation of the {@link Installer}.
*
* <p>It is supposed that installer descriptor and installer script are located as resources in the
* jar.
*
* <p>If resources aren't found then {@link Installer} won't be initialized.
*
* @author Anatolii Bazko
*/
public abstract class BasicInstaller implements Installer {
private final Installer internal;
public BasicInstaller(String installerDescriptor, String installerScript) throws IOException {
internal = readInstallerDescriptor(installerDescriptor, installerScript);
}
@Override
public String getId() {
return internal.getId();
}
@Override
public String getName() {
return internal.getName();
}
@Override
public String getVersion() {
return internal.getVersion();
}
@Override
public String getDescription() {
return internal.getDescription();
}
@Override
public List<String> getDependencies() {
return unmodifiableList(internal.getDependencies());
}
@Override
public String getScript() {
return internal.getScript();
}
@Override
public Map<String, String> getProperties() {
return unmodifiableMap(internal.getProperties());
}
@Override
public Map<String, ? extends ServerConfig> getServers() {
return unmodifiableMap(internal.getServers());
}
private Installer readInstallerDescriptor(String installerDescriptor, String installerScript)
throws IOException {
InputStream inputStream = readResource(installerDescriptor);
InstallerDto installer =
DtoFactory.getInstance().createDtoFromJson(inputStream, InstallerDto.class);
return installer.withScript(readInstallerScript(installerScript));
}
private String readInstallerScript(String installerScript) throws IOException {
InputStream inputStream = readResource(installerScript);
return IoUtil.readStream(inputStream);
}
private InputStream readResource(String resource) throws IOException {
InputStream inputStream = getClass().getResourceAsStream("/" + resource);
if (inputStream == null) {
throw new IOException(format("Can't initialize installer. Resource %s not found", resource));
}
return inputStream;
}
}

View File

@ -31,7 +31,6 @@ import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.eclipse.che.api.core.model.workspace.config.ServerConfig;
import org.eclipse.che.api.installer.server.impl.InstallerFqn;
import org.eclipse.che.api.installer.shared.model.Installer;
/** @author Anatoliy Bazko */
@ -102,7 +101,7 @@ public class InstallerImpl implements Installer {
Map<String, ? extends ServerConfig> servers) {
this.id = id;
this.name = name;
this.version = version == null ? InstallerFqn.DEFAULT_VERSION : version;
this.version = version;
this.description = description;
this.dependencies = dependencies;
this.properties = properties;

View File

@ -11,8 +11,13 @@
package org.eclipse.che.api.installer.server.impl;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import com.google.common.collect.ImmutableList;
import java.util.List;
import org.eclipse.che.api.installer.server.exception.IllegalInstallerKeyException;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
@ -41,4 +46,24 @@ public class InstallerFqnTest {
public void testParseInstallerFqnFails() throws Exception {
InstallerFqn.parse("id:1:2");
}
@Test(dataProvider = "inListData")
public void shouldBeInList(String id, List<String> installerIds) throws Exception {
assertTrue(InstallerFqn.idInKeyList(id, installerIds));
}
@Test(dataProvider = "notInListData")
public void shouldNotBeInList(String id, List<String> installerIds) throws Exception {
assertFalse(InstallerFqn.idInKeyList(id, installerIds));
}
@DataProvider(name = "inListData")
public static Object[][] getInListData() {
return new Object[][] {{"a", ImmutableList.of("a")}, {"a", ImmutableList.of("a:1.0.0")}};
}
@DataProvider(name = "notInListData")
public static Object[][] getNotInListData() {
return new Object[][] {{"a", ImmutableList.of("b")}, {"a:1.0.0", ImmutableList.of("a:1.0.1")}};
}
}

View File

@ -12,7 +12,6 @@ package org.eclipse.che.api.installer.server.impl;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.eclipse.che.api.installer.server.impl.InstallerFqn.DEFAULT_VERSION;
import static org.mockito.Mockito.when;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
@ -46,9 +45,10 @@ public class LocalInstallerRegistryTest {
private LocalInstallerRegistry registry;
@Mock private Installer installer1v1;
@Mock private Installer installer1latest;
@Mock private Installer installer2latest;
@Mock private Installer installer3latest;
@Mock private Installer installer1v2;
@Mock private Installer installer2v1;
@Mock private Installer installer3v1;
@Mock private InstallerValidator installerValidator;
private MapBasedInstallerDao installerDao;
@ -57,21 +57,22 @@ public class LocalInstallerRegistryTest {
installerDao = new MapBasedInstallerDao();
when(installer1v1.getId()).thenReturn("installer1");
when(installer1v1.getVersion()).thenReturn("v1");
when(installer1v1.getVersion()).thenReturn("1.0.0");
when(installer1latest.getId()).thenReturn("installer1");
when(installer1latest.getVersion()).thenReturn("latest");
when(installer1v2.getId()).thenReturn("installer1");
when(installer1v2.getVersion()).thenReturn("2.0.0");
when(installer2latest.getId()).thenReturn("installer2");
when(installer2latest.getVersion()).thenReturn(null); // Default version
when(installer2v1.getId()).thenReturn("installer2");
when(installer2v1.getVersion()).thenReturn("1.0.0"); // Default version
when(installer3latest.getId()).thenReturn("installer3");
when(installer3latest.getVersion()).thenReturn("latest");
when(installer3v1.getId()).thenReturn("installer3");
when(installer3v1.getVersion()).thenReturn("1.0.0");
registry =
new LocalInstallerRegistry(
ImmutableSet.of(installer1v1, installer1latest, installer2latest, installer3latest),
installerDao);
ImmutableSet.of(installer1v1, installer1v2, installer2v1, installer3v1),
installerDao,
installerValidator);
}
@Test(dataProvider = "versions")
@ -87,9 +88,9 @@ public class LocalInstallerRegistryTest {
@DataProvider(name = "versions")
public static Object[][] versions() {
return new Object[][] {
{"installer1", ImmutableSet.of("v1", "latest")},
{"installer2", ImmutableSet.of("latest")},
{"installer3", ImmutableSet.of("latest")}
{"installer1", ImmutableSet.of("1.0.0", "2.0.0")},
{"installer2", ImmutableSet.of("1.0.0")},
{"installer3", ImmutableSet.of("1.0.0")}
};
}
@ -141,7 +142,7 @@ public class LocalInstallerRegistryTest {
List<? extends Installer> items = installers.getItems();
assertEquals(items.size(), 1);
assertTrue(items.contains(new InstallerImpl(installer3latest)));
assertTrue(items.contains(new InstallerImpl(installer1v2)));
}
@Test
@ -155,16 +156,16 @@ public class LocalInstallerRegistryTest {
List<? extends Installer> items = installers.getItems();
assertEquals(items.size(), 2);
assertTrue(items.contains(new InstallerImpl(installer1latest)));
assertTrue(items.contains(new InstallerImpl(installer2latest)));
assertTrue(items.contains(new InstallerImpl(installer2v1)));
assertTrue(items.contains(new InstallerImpl(installer3v1)));
}
@Test
public void shouldReturnEmptyPageIfNoInstallersFound() throws Exception {
registry.remove("installer1:v1");
registry.remove("installer1:latest");
registry.remove("installer2:latest");
registry.remove("installer3:latest");
registry.remove("installer1:1.0.0");
registry.remove("installer1:2.0.0");
registry.remove("installer2:1.0.0");
registry.remove("installer3:1.0.0");
Page<? extends Installer> installers = registry.getInstallers(Integer.MAX_VALUE, 0);
@ -175,19 +176,24 @@ public class LocalInstallerRegistryTest {
assertFalse(installers.hasPreviousPage());
}
@Test(dataProvider = "installerKeys")
public void shouldReturnInstallerByIdAndVersion(String id, String version) throws Exception {
Installer installer = registry.getInstaller(id + (version != null ? ":" + version : ""));
@Test
public void shouldReturnInstallerByIdAndVersion() throws Exception {
Installer installer = registry.getInstaller("installer1:1.0.0");
assertNotNull(installer);
assertNotNull(installer.getVersion());
assertEquals(installer.getId(), id);
assertEquals(installer.getVersion(), version == null ? DEFAULT_VERSION : version);
assertEquals(installer.getId(), "installer1");
assertEquals(installer.getVersion(), "1.0.0");
}
@DataProvider(name = "installerKeys")
public static Object[][] installerKeys() {
return new String[][] {{"installer1", "v1"}, {"installer1", "latest"}, {"installer1", null}};
@Test
public void shouldReturnLatestInstaller() throws Exception {
Installer installer = registry.getInstaller("installer1");
assertNotNull(installer);
assertNotNull(installer.getVersion());
assertEquals(installer.getId(), "installer1");
assertEquals(installer.getVersion(), "2.0.0");
}
@Test(expectedExceptions = InstallerNotFoundException.class)
@ -198,50 +204,67 @@ public class LocalInstallerRegistryTest {
@Test
public void sortInstallersRespectingDependencies() throws Exception {
when(installer1v1.getDependencies()).thenReturn(asList("installer2", "installer3"));
when(installer2latest.getDependencies()).thenReturn(singletonList("installer3"));
when(installer2v1.getDependencies()).thenReturn(singletonList("installer3"));
installerDao.update(new InstallerImpl(installer1v1));
installerDao.update(new InstallerImpl(installer2latest));
installerDao.update(new InstallerImpl(installer2v1));
List<Installer> sorted =
registry.getOrderedInstallers(asList("installer1:v1", "installer2", "installer3"));
registry.getOrderedInstallers(asList("installer1:1.0.0", "installer2", "installer3"));
assertEquals(sorted.size(), 3);
assertEquals(InstallerFqn.of(sorted.get(0)).toString(), "installer3:latest");
assertEquals(InstallerFqn.of(sorted.get(1)).toString(), "installer2:latest");
assertEquals(InstallerFqn.of(sorted.get(2)).toString(), "installer1:v1");
assertEquals(InstallerFqn.of(sorted.get(0)).toString(), "installer3:1.0.0");
assertEquals(InstallerFqn.of(sorted.get(1)).toString(), "installer2:1.0.0");
assertEquals(InstallerFqn.of(sorted.get(2)).toString(), "installer1:1.0.0");
}
@Test
public void shouldReturnInstallerAlongWithItsTransitiveDependenciesOnSorting() throws Exception {
when(installer1v1.getDependencies()).thenReturn(singletonList("installer2:latest"));
when(installer2latest.getDependencies()).thenReturn(singletonList("installer3"));
when(installer1v1.getDependencies()).thenReturn(singletonList("installer2:1.0.0"));
when(installer2v1.getDependencies()).thenReturn(singletonList("installer3"));
installerDao.update(new InstallerImpl(installer1v1));
installerDao.update(new InstallerImpl(installer2latest));
installerDao.update(new InstallerImpl(installer2v1));
List<Installer> sorted = registry.getOrderedInstallers(singletonList("installer1:v1"));
List<Installer> sorted = registry.getOrderedInstallers(singletonList("installer1:1.0.0"));
assertEquals(sorted.size(), 3);
assertEquals(InstallerFqn.of(sorted.get(0)).toString(), "installer3:latest");
assertEquals(InstallerFqn.of(sorted.get(1)).toString(), "installer2:latest");
assertEquals(InstallerFqn.of(sorted.get(2)).toString(), "installer1:v1");
assertEquals(InstallerFqn.of(sorted.get(0)).toString(), "installer3:1.0.0");
assertEquals(InstallerFqn.of(sorted.get(1)).toString(), "installer2:1.0.0");
assertEquals(InstallerFqn.of(sorted.get(2)).toString(), "installer1:1.0.0");
}
@Test(
expectedExceptions = InstallerException.class,
expectedExceptionsMessageRegExp =
"Installers circular dependency found between 'installer1:v1'" + " and 'installer3:latest'"
"Installers circular dependency found between 'installer1:1.0.0'"
+ " and 'installer3:1.0.0'"
)
public void sortingShouldFailIfCircularDependenciesFound() throws Exception {
when(installer1v1.getDependencies()).thenReturn(singletonList("installer2:latest"));
when(installer2latest.getDependencies()).thenReturn(singletonList("installer3:latest"));
when(installer3latest.getDependencies()).thenReturn(singletonList("installer1:v1"));
when(installer1v1.getDependencies()).thenReturn(singletonList("installer2:1.0.0"));
when(installer2v1.getDependencies()).thenReturn(singletonList("installer3:1.0.0"));
when(installer3v1.getDependencies()).thenReturn(singletonList("installer1:1.0.0"));
installerDao.update(new InstallerImpl(installer1v1));
installerDao.update(new InstallerImpl(installer2latest));
installerDao.update(new InstallerImpl(installer3latest));
installerDao.update(new InstallerImpl(installer2v1));
installerDao.update(new InstallerImpl(installer3v1));
registry.getOrderedInstallers(asList("installer1:v1", "installer2", "installer3:latest"));
registry.getOrderedInstallers(
asList("installer1:1.0.0", "installer2:1.0.0", "installer3:1.0.0"));
}
@Test(
expectedExceptions = InstallerException.class,
expectedExceptionsMessageRegExp =
"Installers dependencies conflict. Several version '2.0.0' and '1.0.0' of the some id 'installer1"
)
public void shouldNotReturnOrderedSeveralInstallersDifferentVersions() throws Exception {
when(installer2v1.getDependencies()).thenReturn(singletonList("installer1:1.0.0"));
when(installer3v1.getDependencies()).thenReturn(singletonList("installer1:2.0.0"));
installerDao.update(new InstallerImpl(installer2v1));
installerDao.update(new InstallerImpl(installer3v1));
registry.getOrderedInstallers(asList("installer2:1.0.0", "installer3:1.0.0"));
}
}

View File

@ -11,7 +11,7 @@
package org.eclipse.che.api.installer.server.impl;
import com.google.inject.Inject;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@ -34,7 +34,7 @@ public class MapBasedInstallerDao implements InstallerDao {
@Inject
public MapBasedInstallerDao() {
this.installers = new HashMap<>();
this.installers = new LinkedHashMap<>();
}
@Override

View File

@ -52,11 +52,13 @@ public class RemoteInstallerRegistryTest {
@BeforeMethod
public void setUp(ITestContext context) throws Exception {
installer = TestInstallerFactory.createInstaller("id_0", "version_0");
installer = TestInstallerFactory.createInstaller("id_0", "1.0.0");
installerKey = InstallerFqn.of(installer).toKey();
LocalInstallerRegistry localInstallerRegistry =
new LocalInstallerRegistry(Collections.singleton(installer), new MapBasedInstallerDao());
new LocalInstallerRegistry(
Collections.singleton(installer), new MapBasedInstallerDao(), new InstallerValidator());
registryService = new InstallerRegistryService(localInstallerRegistry);
Integer port = (Integer) context.getAttribute(EverrestJetty.JETTY_PORT);
@ -67,7 +69,7 @@ public class RemoteInstallerRegistryTest {
@Test
public void shouldAddNewInstaller() throws Exception {
InstallerImpl newInstaller = TestInstallerFactory.createInstaller("id_1", "version_1");
InstallerImpl newInstaller = TestInstallerFactory.createInstaller("id_1", "1.0.1");
String newInstallerKey = InstallerFqn.of(newInstaller).toKey();
registry.add(newInstaller);
@ -82,7 +84,7 @@ public class RemoteInstallerRegistryTest {
@Test
public void shouldUpdateInstaller() throws Exception {
InstallerImpl newInstaller = TestInstallerFactory.createInstaller("id_0", "version_0");
InstallerImpl newInstaller = TestInstallerFactory.createInstaller("id_0", "1.0.0");
String newInstallerKey = InstallerFqn.of(newInstaller).toKey();
registry.update(newInstaller);
@ -93,7 +95,7 @@ public class RemoteInstallerRegistryTest {
@Test(expectedExceptions = InstallerNotFoundException.class)
public void shouldThrowInstallerNotFoundExceptionOnUpdatingIfInstallerDoesNotExist()
throws Exception {
InstallerImpl newInstaller = TestInstallerFactory.createInstaller("id_1", "version_1");
InstallerImpl newInstaller = TestInstallerFactory.createInstaller("id_1", "1.0.1");
registry.update(newInstaller);
}
@ -153,8 +155,8 @@ public class RemoteInstallerRegistryTest {
@Test
public void shouldReturnFirstPage() throws Exception {
InstallerImpl installer1 = TestInstallerFactory.createInstaller("id_1", "version_1");
InstallerImpl installer2 = TestInstallerFactory.createInstaller("id_2", "version_2");
InstallerImpl installer1 = TestInstallerFactory.createInstaller("id_1", "1.0.1");
InstallerImpl installer2 = TestInstallerFactory.createInstaller("id_2", "1.0.2");
registry.add(installer1);
registry.add(installer2);
@ -176,8 +178,8 @@ public class RemoteInstallerRegistryTest {
@Test
public void shouldReturnMiddlePage() throws Exception {
InstallerImpl installer1 = TestInstallerFactory.createInstaller("id_1", "version_1");
InstallerImpl installer2 = TestInstallerFactory.createInstaller("id_2", "version_2");
InstallerImpl installer1 = TestInstallerFactory.createInstaller("id_1", "1.0.1");
InstallerImpl installer2 = TestInstallerFactory.createInstaller("id_2", "1.0.2");
registry.add(installer1);
registry.add(installer2);
@ -203,8 +205,8 @@ public class RemoteInstallerRegistryTest {
@Test
public void shouldReturnLastPage() throws Exception {
InstallerImpl installer1 = TestInstallerFactory.createInstaller("id_1", "version_1");
InstallerImpl installer2 = TestInstallerFactory.createInstaller("id_2", "version_2");
InstallerImpl installer1 = TestInstallerFactory.createInstaller("id_1", "1.0.1");
InstallerImpl installer2 = TestInstallerFactory.createInstaller("id_2", "1.0.2");
registry.add(installer1);
registry.add(installer2);
@ -238,19 +240,19 @@ public class RemoteInstallerRegistryTest {
@Test
public void shouldReturnOrderedInstallers() throws Exception {
InstallerImpl installer1 = TestInstallerFactory.createInstaller("id_1", "version_1");
InstallerImpl installer2 = TestInstallerFactory.createInstaller("id_2", "version_2");
InstallerImpl installer1 = TestInstallerFactory.createInstaller("id_1", "1.0.1");
InstallerImpl installer2 = TestInstallerFactory.createInstaller("id_2", "1.0.2");
installer.setDependencies(Collections.emptyList());
installer1.setDependencies(Collections.singletonList("id_0:version_0"));
installer2.setDependencies(Collections.singletonList("id_1:version_1"));
installer1.setDependencies(Collections.singletonList("id_0:1.0.0"));
installer2.setDependencies(Collections.singletonList("id_1:1.0.1"));
registry.update(installer);
registry.add(installer1);
registry.add(installer2);
List<Installer> orderedInstallers =
registry.getOrderedInstallers(ImmutableList.of("id_2:version_2"));
registry.getOrderedInstallers(ImmutableList.of("id_2:1.0.2"));
assertEquals(orderedInstallers.size(), 3);
assertInstaller(orderedInstallers.get(0), installer);

View File

@ -54,7 +54,7 @@ public class InstallerDaoTest {
installers = new InstallerImpl[INSTALLER_COUNT];
for (int i = 0; i < installers.length; i++) {
installers[i] = TestInstallerFactory.createInstaller("id_" + i, "version_" + i);
installers[i] = TestInstallerFactory.createInstaller("id_" + i, "1.0." + i);
}
tckRepository.createAll(asList(installers));
@ -67,7 +67,7 @@ public class InstallerDaoTest {
@Test
public void shouldGetInstallerByFqn() throws Exception {
final InstallerFqn fqn = new InstallerFqn("id_0", "version_0");
final InstallerFqn fqn = new InstallerFqn("id_0", "1.0.0");
assertEquals(new InstallerImpl(installers[0]), installerDao.getByFqn(fqn));
}
@ -88,7 +88,7 @@ public class InstallerDaoTest {
@Test(expectedExceptions = InstallerNotFoundException.class)
public void shouldThrowNotFoundExceptionWhenGettingInstallerByWrongId() throws Exception {
final InstallerFqn fqn = new InstallerFqn("non-existed", "version_0");
final InstallerFqn fqn = new InstallerFqn("non-existed", "1.0.0");
installerDao.getByFqn(fqn);
}
@ -107,7 +107,7 @@ public class InstallerDaoTest {
public void shouldReturnAllInstallersBySpecificId() throws Exception {
List<String> result = installerDao.getVersions("id_0");
assertEquals(result.size(), 1);
assertEquals(result.get(0), "version_0");
assertEquals(result.get(0), "1.0.0");
}
@Test
@ -156,12 +156,12 @@ public class InstallerDaoTest {
@Test
public void shouldCreateInstaller() throws Exception {
InstallerImpl newInstaller = TestInstallerFactory.createInstaller("id_new", "version_new");
InstallerImpl newInstaller = TestInstallerFactory.createInstaller("id_new", "1.0.0");
installerDao.create(newInstaller);
assertEquals(
installerDao.getByFqn(new InstallerFqn("id_new", "version_new")),
installerDao.getByFqn(new InstallerFqn("id_new", "1.0.0")),
new InstallerImpl(newInstaller));
}
@ -185,13 +185,12 @@ public class InstallerDaoTest {
installerDao.update(updatedInstaller);
assertEquals(installerDao.getByFqn(new InstallerFqn("id_0", "version_0")), updatedInstaller);
assertEquals(installerDao.getByFqn(new InstallerFqn("id_0", "1.0.0")), updatedInstaller);
}
@Test(expectedExceptions = InstallerNotFoundException.class)
public void shouldThrowNotFoundExceptionWhenUpdatingNonExistingInstaller() throws Exception {
InstallerImpl updatedInstaller =
TestInstallerFactory.createInstaller("non-existed", "non-existed");
InstallerImpl updatedInstaller = TestInstallerFactory.createInstaller("non-existed", "1.0.0");
installerDao.update(updatedInstaller);
}
@ -203,7 +202,7 @@ public class InstallerDaoTest {
@Test(expectedExceptions = InstallerNotFoundException.class)
public void shouldRemoveInstaller() throws Exception {
InstallerFqn fqn = new InstallerFqn("id_0", "version_0");
InstallerFqn fqn = new InstallerFqn("id_0", "1.0.0");
installerDao.remove(fqn);
installerDao.getByFqn(fqn);

View File

@ -11,7 +11,9 @@
package org.eclipse.che.api.agent.server.filters;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.eclipse.che.api.installer.server.impl.InstallerFqn;
import org.eclipse.che.api.workspace.shared.dto.EnvironmentDto;
import org.eclipse.che.api.workspace.shared.dto.MachineConfigDto;
import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto;
@ -31,8 +33,7 @@ public class AddExecInstallerInEnvironmentUtil {
if (environment != null && environment.getMachines() != null) {
for (MachineConfigDto machine : environment.getMachines().values()) {
if (machine.getInstallers() != null) {
if (machine.getInstallers().contains("org.eclipse.che.terminal")
&& !machine.getInstallers().contains("org.eclipse.che.exec")) {
if (containsTerminalInstallerWithoutExec(machine.getInstallers())) {
ArrayList<String> updatedInstallers = new ArrayList<>(machine.getInstallers());
updatedInstallers.add("org.eclipse.che.exec");
machine.setInstallers(updatedInstallers);
@ -44,4 +45,9 @@ public class AddExecInstallerInEnvironmentUtil {
}
}
}
private static boolean containsTerminalInstallerWithoutExec(List<String> installers) {
return InstallerFqn.idInKeyList("org.eclipse.che.terminal", installers)
&& !(InstallerFqn.idInKeyList("org.eclipse.che.exec", installers));
}
}

View File

@ -8,12 +8,13 @@
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.api.workspace.shared;
package org.eclipse.che.api.workspace.server;
import java.util.List;
import java.util.Map;
import org.eclipse.che.api.core.model.workspace.config.Environment;
import org.eclipse.che.api.core.model.workspace.config.MachineConfig;
import org.eclipse.che.api.installer.server.impl.InstallerFqn;
/**
* Utility class for workspace related code that might be useful on server or GWT client.
@ -50,6 +51,6 @@ public class Utils {
*/
public static boolean isDev(MachineConfig machineConf) {
final List<String> installers = machineConf.getInstallers();
return installers != null && installers.contains(WSAGENT_INSTALLER);
return InstallerFqn.idInKeyList(WSAGENT_INSTALLER, installers);
}
}