Permalink
Browse files

ROO-2986: Post 1.2.0.RELEASE code refactor and clean up - applied ER …

…cleanup profile
  • Loading branch information...
1 parent fc1f2ca commit fb3e99c4b2b9bb43ec19b799620c05d01854f4bb Alan Stewart committed Jan 11, 2012
Showing 792 changed files with 43,621 additions and 43,754 deletions.
@@ -17,16 +17,15 @@
@Service
public class BackupCommands implements CommandMarker {
- // Fields
@Reference private BackupOperations backupOperations;
- @CliAvailabilityIndicator("backup")
- public boolean isBackupCommandAvailable() {
- return backupOperations.isBackupPossible();
- }
-
@CliCommand(value = "backup", help = "Backup your project to a zip file")
public String backup() {
return backupOperations.backup();
}
+
+ @CliAvailabilityIndicator("backup")
+ public boolean isBackupCommandAvailable() {
+ return backupOperations.isBackupPossible();
+ }
}
@@ -8,7 +8,7 @@
*/
public interface BackupOperations {
- boolean isBackupPossible();
-
String backup();
+
+ boolean isBackupPossible();
}
@@ -38,18 +38,12 @@
@Service
public class BackupOperationsImpl implements BackupOperations {
- // Constants
private static final Logger LOGGER = HandlerUtils
.getLogger(BackupOperationsImpl.class);
- // Fields
@Reference private FileManager fileManager;
@Reference private ProjectOperations projectOperations;
- public boolean isBackupPossible() {
- return projectOperations.isFocusedProjectAvailable();
- }
-
public String backup() {
Assert.isTrue(isBackupPossible(), "Project metadata unavailable");
@@ -58,33 +52,37 @@ public String backup() {
final String pattern = File.separatorChar == '\\' ? "yyyy-MM-dd_HH.mm.ss"
: "yyyy-MM-dd_HH:mm:ss";
final DateFormat df = new SimpleDateFormat(pattern);
- long start = System.nanoTime();
+ final long start = System.nanoTime();
ZipOutputStream zos = null;
try {
- File projectDirectory = new File(projectOperations
+ final File projectDirectory = new File(projectOperations
.getPathResolver().getFocusedIdentifier(Path.ROOT, "."));
- MutableFile file = fileManager.createFile(FileUtils
+ final MutableFile file = fileManager.createFile(FileUtils
.getCanonicalPath(new File(projectDirectory,
projectOperations.getFocusedProjectName() + "_"
+ df.format(new Date()) + ".zip")));
zos = new ZipOutputStream(file.getOutputStream());
zip(projectDirectory, projectDirectory, zos);
}
- catch (FileNotFoundException e) {
+ catch (final FileNotFoundException e) {
LOGGER.fine("Could not determine project directory");
}
- catch (IOException e) {
+ catch (final IOException e) {
LOGGER.fine("Could not create backup archive");
}
finally {
IOUtils.closeQuietly(zos);
}
- long milliseconds = (System.nanoTime() - start) / 1000000;
+ final long milliseconds = (System.nanoTime() - start) / 1000000;
return "Backup completed in " + milliseconds + " ms";
}
+ public boolean isBackupPossible() {
+ return projectOperations.isFocusedProjectAvailable();
+ }
+
private void zip(final File directory, final File base,
final ZipOutputStream zos) throws IOException {
final File[] files = directory.listFiles(new FilenameFilter() {
@@ -104,25 +102,25 @@ public boolean accept(final File dir, final String name) {
}
});
- byte[] buffer = new byte[8192];
+ final byte[] buffer = new byte[8192];
int read = 0;
- for (int i = 0, n = files.length; i < n; i++) {
- if (files[i].isDirectory()) {
- if (files[i].listFiles().length == 0) {
- ZipEntry dirEntry = new ZipEntry(files[i].getPath()
+ for (final File file : files) {
+ if (file.isDirectory()) {
+ if (file.listFiles().length == 0) {
+ final ZipEntry dirEntry = new ZipEntry(file.getPath()
.substring(base.getPath().length() + 1)
+ File.separatorChar);
zos.putNextEntry(dirEntry);
}
- zip(files[i], base, zos);
+ zip(file, base, zos);
}
else {
InputStream inputStream = null;
try {
inputStream = new BufferedInputStream(new FileInputStream(
- files[i]));
- ZipEntry entry = new ZipEntry(files[i].getPath().substring(
- base.getPath().length() + 1));
+ file));
+ final ZipEntry entry = new ZipEntry(file.getPath()
+ .substring(base.getPath().length() + 1));
zos.putNextEntry(entry);
while ((read = inputStream.read(buffer)) != -1) {
zos.write(buffer, 0, read);
@@ -24,19 +24,17 @@
@Service
public class AppCloudClientFactoryImpl implements AppCloudClientFactory {
- // Constants
private static final String CLOUD_FOUNDRY_PRODUCT_NAME = "Cloud Foundry Java API";
private static final String DEFAULT_BUNDLE_VERSION = "0.0.0.RELEASE";
- // Fields
- @Reference UaaService uaaService;
// TODO is this value ever used, or is it always overwritten by activate()?
private Product product = VersionHelper.getProduct(
CLOUD_FOUNDRY_PRODUCT_NAME, DEFAULT_BUNDLE_VERSION);
+ @Reference UaaService uaaService;
protected void activate(final ComponentContext context) {
- this.product = getCloudFoundryProduct(context.getBundleContext()
- .getBundle().getHeaders());
+ product = getCloudFoundryProduct(context.getBundleContext().getBundle()
+ .getHeaders());
}
private Product getCloudFoundryProduct(final Dictionary<?, ?> bundleHeaders) {
@@ -14,29 +14,37 @@
*/
public class CloudCredentials {
- // Constants
private static final String EMAIL_KEY = "email";
private static final String PASSWORD_KEY = "password";
private static final String URL_KEY = "url";
- // Fields
+ public static CloudCredentials decode(final String encoded) {
+ if (StringUtils.isBlank(encoded)) {
+ throw new IllegalStateException(
+ "Stored login invalid; cannot continue");
+ }
+ final Map<String, String> map = new HashMap<String, String>();
+ final String[] encodedFields = encoded.split(",");
+ for (final String encodedField : encodedFields) {
+ final String[] valuePair = encodedField.split(":");
+ if (valuePair.length == 2) {
+ try {
+ map.put(valuePair[0],
+ new String(Base64.decode(valuePair[1],
+ Base64.DO_BREAK_LINES)));
+ }
+ catch (final IOException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+ return new CloudCredentials(map);
+ }
+
private final String email;
private final String password;
- private final String url;
- /**
- * Constructor that accepts distinct values
- *
- * @param email the email address with which to log in (can be blank)
- * @param password the password for that email address (can be blank)
- * @param url the URL to log into (can be blank)
- */
- public CloudCredentials(final String email, final String password,
- final String url) {
- this.email = email;
- this.password = password;
- this.url = url;
- }
+ private final String url;
/**
* Constructor that reads the relevant entries of the given map
@@ -49,55 +57,17 @@ public CloudCredentials(final Map<String, String> properties) {
}
/**
- * Indicates whether these credentials are complete, i.e. contain enough
- * information to attempt a login
- *
- * @return see above
- */
- public boolean isValid() {
- return StringUtils.hasText(email) && StringUtils.hasText(password)
- && StringUtils.hasText(url);
- }
-
- public String getEmail() {
- return email;
- }
-
- public String getPassword() {
- return password;
- }
-
- public String getUrl() {
- return url;
- }
-
- /**
- * Indicates whether the given account details match these credentials
- *
- * @param url the URL to check (can be <code>null</code>)
- * @param email the email to check (can be <code>null</code>)
- * @return see above
- */
- public boolean isSameAccount(final String url, final String email) {
- return StringUtils.equals(url, this.url)
- && StringUtils.equals(email, this.email);
- }
-
- /**
- * Returns the URL for these credentials
+ * Constructor that accepts distinct values
*
- * @return <code>null</code> if none is set
+ * @param email the email address with which to log in (can be blank)
+ * @param password the password for that email address (can be blank)
+ * @param url the URL to log into (can be blank)
*/
- public URL getUrlObject() {
- if (StringUtils.hasText(this.url)) {
- try {
- return new URL(this.url);
- }
- catch (final MalformedURLException e) {
- throw new IllegalStateException(e);
- }
- }
- return null;
+ public CloudCredentials(final String email, final String password,
+ final String url) {
+ this.email = email;
+ this.password = password;
+ this.url = url;
}
public String encode() {
@@ -126,52 +96,85 @@ public String encode() {
return sb.toString();
}
- public static CloudCredentials decode(final String encoded) {
- if (StringUtils.isBlank(encoded)) {
- throw new IllegalStateException(
- "Stored login invalid; cannot continue");
- }
- final Map<String, String> map = new HashMap<String, String>();
- final String[] encodedFields = encoded.split(",");
- for (final String encodedField : encodedFields) {
- final String[] valuePair = encodedField.split(":");
- if (valuePair.length == 2) {
- try {
- map.put(valuePair[0],
- new String(Base64.decode(valuePair[1],
- Base64.DO_BREAK_LINES)));
- }
- catch (final IOException e) {
- throw new IllegalStateException(e);
- }
- }
- }
- return new CloudCredentials(map);
- }
-
@Override
public boolean equals(final Object o) {
- if (this == o)
+ if (this == o) {
return true;
- if (o == null || getClass() != o.getClass())
+ }
+ if ((o == null) || (getClass() != o.getClass())) {
return false;
+ }
final CloudCredentials clouldCredentials = (CloudCredentials) o;
if (email != null ? !email.equals(clouldCredentials.email)
- : clouldCredentials.email != null)
+ : clouldCredentials.email != null) {
return false;
+ }
if (url != null ? !url.equals(clouldCredentials.url)
- : clouldCredentials.url != null)
+ : clouldCredentials.url != null) {
return false;
+ }
return true;
}
+ public String getEmail() {
+ return email;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public String getUrl() {
+ return url;
+ }
+
+ /**
+ * Returns the URL for these credentials
+ *
+ * @return <code>null</code> if none is set
+ */
+ public URL getUrlObject() {
+ if (StringUtils.hasText(url)) {
+ try {
+ return new URL(url);
+ }
+ catch (final MalformedURLException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return null;
+ }
+
@Override
public int hashCode() {
int result = email != null ? email.hashCode() : 0;
- result = 31 * result + (url != null ? url.hashCode() : 0);
+ result = (31 * result) + (url != null ? url.hashCode() : 0);
return result;
}
+
+ /**
+ * Indicates whether the given account details match these credentials
+ *
+ * @param url the URL to check (can be <code>null</code>)
+ * @param email the email to check (can be <code>null</code>)
+ * @return see above
+ */
+ public boolean isSameAccount(final String url, final String email) {
+ return StringUtils.equals(url, this.url)
+ && StringUtils.equals(email, this.email);
+ }
+
+ /**
+ * Indicates whether these credentials are complete, i.e. contain enough
+ * information to attempt a login
+ *
+ * @return see above
+ */
+ public boolean isValid() {
+ return StringUtils.hasText(email) && StringUtils.hasText(password)
+ && StringUtils.hasText(url);
+ }
}
Oops, something went wrong.

0 comments on commit fb3e99c

Please sign in to comment.