blob: ee16ac5d314af52c7de271a48f199179b56a450e [file] [log] [blame]
/*
* Copyright (C) 2016 The Android Open Source Project
*
* 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.android.jack.library;
import com.android.sched.util.codec.ListCodec;
import com.android.sched.util.config.id.PropertyId;
import java.io.File;
import java.util.List;
import javax.annotation.Nonnull;
/**
* Specialized {@link PropertyId} that manages properties representing a Library path.
*/
public class LibraryPathPropertyId extends PropertyId<List<InputLibrary>> {
public LibraryPathPropertyId(
@Nonnull String name, @Nonnull String description, @Nonnull String infoString) {
super(
name,
description,
new ListCodec<InputLibrary>(new InputLibraryCodec().setInfoString(infoString))
.setMin(0)
.setSeparator(File.pathSeparator));
withAutoCheck();
}
@Nonnull
private LibraryPathPropertyId withAutoCheck() {
setShutdownHook(
new ShutdownRunnable<List<InputLibrary>>() {
@Override
public void run(@Nonnull List<InputLibrary> inputLibList) {
for (InputLibrary library : inputLibList) {
if (!library.isClosed()) {
throw new AssertionError("Library "
+ library.getLocation().getDescription()
+ " from property '"
+ getName()
+ "' is not closed");
}
}
}
});
return this;
}
@Nonnull
public LibraryPathPropertyId withoutAutoAction() {
removeShutdownHook();
return this;
}
@Override
@Nonnull
public LibraryPathPropertyId addDefaultValue(@Nonnull List<InputLibrary> defaultValue) {
super.addDefaultValue(defaultValue);
return this;
}
@Override
@Nonnull
public ListCodec<InputLibrary> getCodec() {
return (ListCodec<InputLibrary>) super.getCodec();
}
}