blob: ea4a80e6883cab1003b11efd9464142f1655e3d6 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2008 Innoopract Informationssysteme GmbH.
* 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:
* Innoopract Informationssysteme GmbH - initial API and implementation
******************************************************************************/
package org.eclipse.epp.wizard.internal;
import java.io.File;
import java.io.IOException;
import java.util.Properties;
import org.apache.log4j.Logger;
public class Configuration {
static Logger logger = Logger.getLogger( Configuration.class );
final static String MODEL = "model";
final static String EXTERNAL_SERVICE_PROVIDERS = "externalServiceProviders";
final static String EPP_METADATA_REPOSITORY = "epp.metadata";
final static String INSTALLER_URL = "installer.url";
final static String WEBSTART_URL = "webstart.url";
final static String BASE_IUS = "baseIUs";
final static String TERMS_OF_USE_URL = "termsofuse.url";
final static String TERMS_OF_USE_URL_DEFAULT = "http://www.eclipse.org/legal/termsofuse.php";
final static String PRIVACY_URL = "privacy.url";
final static String PRIVACY_URL_DEFAULT = "http://www.eclipse.org/legal/privacy.php";
final static String STATS_LOGGING_FILE = "stats.logging.file";
final static String STATS_LOGGING_FILE_DEFAULT = "stats.txt";
final public static String P2_METADATA_REPOSITORIES = "eclipse.p2.metadata";
final public static String P2_ARTIFACT_REPOSITORIES = "eclipse.p2.artifacts";
final public static String P2_ROOTS = "eclipse.p2.roots";
protected File modelDirectory;
protected File externalServiceProviderDirectory;
protected String eppMetadataRepository;
protected String installerURL;
protected String webstarterURL;
protected String baseIUs;
protected String termsOfUseURL;
public String getTermsOfUseURL() {
return termsOfUseURL;
}
public void setTermsOfUseURL( String termsOfUseURL ) {
this.termsOfUseURL = termsOfUseURL;
}
public File getStatsLoggingFile() {
return statsLoggingFile;
}
public void setStatsLoggingFile( File statsLoggingFile ) {
this.statsLoggingFile = statsLoggingFile;
}
protected File statsLoggingFile;
public String getBaseIUs() {
return baseIUs;
}
public String getInstallerURL() {
return installerURL;
}
public String getWebstarterURL() {
return webstarterURL;
}
public String getEppMetadataRepository() {
return eppMetadataRepository;
}
protected String metadataRepositories;
protected String artifactRepositories;
public String getMetadataRepositories() {
return metadataRepositories;
}
public String getArtifactRepositories() {
return artifactRepositories;
}
protected ExternalServiceProviderConfiguration externalServiceProviderConfiguration;
public ExternalServiceProviderConfiguration getExternalServiceProviderConfiguration()
{
return externalServiceProviderConfiguration;
}
private Properties properties;
private String privacyURL;
public String getPrivacyURL() {
return privacyURL;
}
public File getModelDirectory() {
return modelDirectory;
}
public File getExternalServiceProviderDirectory() {
return externalServiceProviderDirectory;
}
public Configuration( Properties properties ) {
this.properties = properties;
modelDirectory = createDirectoryObject( MODEL );
externalServiceProviderDirectory = createDirectoryObject( EXTERNAL_SERVICE_PROVIDERS );
loadExternalServiceProviderConfiguration();
installerURL = properties.getProperty( INSTALLER_URL );
webstarterURL = properties.getProperty( WEBSTART_URL );
metadataRepositories = properties.getProperty( P2_METADATA_REPOSITORIES );
artifactRepositories = properties.getProperty( P2_ARTIFACT_REPOSITORIES );
eppMetadataRepository = properties.getProperty( EPP_METADATA_REPOSITORY );
baseIUs = properties.getProperty( BASE_IUS, "" );
termsOfUseURL = properties.getProperty( TERMS_OF_USE_URL,
TERMS_OF_USE_URL_DEFAULT );
privacyURL = properties.getProperty( PRIVACY_URL, PRIVACY_URL_DEFAULT );
statsLoggingFile = new File( properties.getProperty( STATS_LOGGING_FILE,
STATS_LOGGING_FILE_DEFAULT ) );
try {
statsLoggingFile.createNewFile();
} catch( IOException e ) {
throw new RuntimeException( "Unable to create stats logging file", e );
}
if( !statsLoggingFile.canWrite() ) {
throw new RuntimeException( "Cannot write to stats logging file '"
+ statsLoggingFile.getAbsolutePath()
+ "'" );
}
if( logger.isInfoEnabled() ) {
StringBuilder sb = new StringBuilder();
sb.append( "EPP Wizard configuration:" );
sb.append( "\n\t modelDirectory: "
+ modelDirectory.getAbsolutePath() );
sb.append( "\n\t externalServiceProviderDirectory: "
+ externalServiceProviderDirectory.getAbsolutePath() );
sb.append( "\n\t metadataRepositories: "
+ metadataRepositories );
sb.append( "\n\t artifactRepositories: "
+ artifactRepositories );
sb.append( "\n\t baseIUs: " + baseIUs );
sb.append( "\n\t installerURL: " + installerURL );
sb.append( "\n\t statsLoggingFile: " + statsLoggingFile );
sb.append( "\n\t termsOfUseURL: " + termsOfUseURL );
logger.info( sb );
}
}
private void loadExternalServiceProviderConfiguration() {
externalServiceProviderConfiguration = new ExternalServiceProviderConfiguration( externalServiceProviderDirectory );
}
private File createDirectoryObject( String key ) {
String value = properties.getProperty( key );
if( value == null ) {
throw new RuntimeException( "Configuration value for '"
+ key
+ "' not defined in configuration properties" );
}
File file = new File( value );
if( !file.isDirectory() ) {
throw new RuntimeException( "'"
+ file.getAbsolutePath()
+ "' is not a directory" );
}
if( !file.canRead() ) {
throw new RuntimeException( "Cannot read from directory '"
+ file.getAbsolutePath()
+ "'" );
}
return file;
}
}